backbone-emulate-collection
Mix in methods from Underscore, for iteration, and other collection related features. Borrowing this code from Backbone.Collection.
It works by taking an object and a property field, in this example 'list',
and appending collection functions to the object so that it can
delegate collection calls to its list.
Object Literal
var obj = {
list: [1, 2, 3]
}
emulateCollection(obj, 'list');
var double = function(v){ return v*2; };
console.log(obj.map(double));
Function Prototype
var Func = function(list) {
this.list = list;
};
emulateCollection(Func.prototype, 'list');
var func = new Func([1,2,3]);
var double = function(v){ return v*2; };
console.log(func.map(double));
For more information about the proxied methods, see the Underscore.js documentation.