npm

Need private packages and team management tools?Check out npm Orgs. »

backbone-emulate-collection

0.1.0 • Public • Published

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.

Keywords

none

install

npm i backbone-emulate-collection

Downloadsweekly downloads

1

version

0.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability