Created
February 26, 2011 23:17
-
-
Save samdelagarza/845728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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