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.

/backbone-emulate-collection/

    Package Sidebar

    Install

    npm i backbone-emulate-collection

    Weekly Downloads

    2

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • paulfalgout