I\'m learning Backbone, which uses Underscore.
In some examples, I see initialization code to create an empty array of children like this:
// inside
Because this.children
needs to be a instance of underscore: a specialized class that wraps an array, not just a regular javascript array literal. The code in the _
function just makes sure it's always one _
instance wrapping one regular array, even if you try to rewrap an underscore instance repeatedly, call _ with or without the new
keyword.
//new _ instance wrapping an array. Straightforward.
var _withNew = new _([]);
//automatically calls `new` for you and returns that, resulting in same as above
var _withoutNew = _([]);
//just gives you _withoutNew back since it's already a proper _ instance
var _doubleWrapped = _(_withoutNew);