Skip to content
This repository has been archived by the owner on Oct 10, 2017. It is now read-only.

marionettejs/backbone-emulate-collection

Repository files navigation

backbone-emulate-collection

Travis build status Code Climate Test Coverage Dependency Status

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)); // [2, 4, 6]

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)); // [2, 4, 6]

For more information about the proxied methods, see the Underscore.js documentation.

About

Proxies underscore events to match a Backbone.Collection

Resources

License

Stars

Watchers

Forks

Packages

No packages published