From 8c58820406a7a607c38612cff4d0fa2625ec73c6 Mon Sep 17 00:00:00 2001 From: Daniel Hug Date: Sat, 30 Jan 2016 16:49:10 -0800 Subject: [PATCH] calling with 'new' is optional --- observable-array.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/observable-array.js b/observable-array.js index 3112256..41efcf2 100644 --- a/observable-array.js +++ b/observable-array.js @@ -8,6 +8,11 @@ var ObservableArray = (function() { */ function ObservableArray(collection) { + // calling with `new` is optional + if (!(this instanceof ObservableArray)) { + return new ObservableArray(collection); + } + // add items from passed `collection` to `this` collection = collection || []; for (var i = 0; i < collection.length; i++) {