Skip to content

Commit

Permalink
calling with 'new' is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Hug committed Jan 31, 2016
1 parent 855d740 commit 8c58820
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions observable-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit 8c58820

Please sign in to comment.