Skip to content

Instantly share code, notes, and snippets.

@samdelagarza
Created February 26, 2011 23:17
Show Gist options
  • Save samdelagarza/845728 to your computer and use it in GitHub Desktop.
Save samdelagarza/845728 to your computer and use it in GitHub Desktop.
// events simply proxy through.
_onModelEvent : function(ev, model) {
if (ev === 'change:id') {
delete this._byId[model.previous('id')];
this._byId[model.id] = model;
}
this.trigger.apply(this, arguments);
}
});
console.log("begin");
var tmp = Backbone.Collection;
console.log(tmp._reset());
console.log("end");
// Underscore methods that we want to implement on the Collection.
var methods = ['forEach', 'each', 'map', 'reduce', 'reduceRight', 'find', 'detect',
'filter', 'select', 'reject', 'every', 'all', 'some', 'any', 'include',
'invoke', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size',
'first', 'rest', 'last', 'without', 'indexOf', 'lastIndexOf', 'isEmpty'];
// Mix in each Underscore method as a proxy to `Collection#models`.
_.each(methods, function(method) {
Backbone.Collection.prototype[method] = function() {
return _[method].apply(_, [this.models].concat(_.toArray(arguments)));
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment