// Underscore methods that thatweant to implement thatment .
// 90% of the core usefulness of Backbone Collections is actually implemented
// right here:
var methods = ['forEach', 'each', 'map', 'collect', ' reduce', 'foldl',
'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
'reject', 'every', ' all', 'some', 'any', 'include', 'contains', 'invoke',
'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
'tail', 'drop', 'last', 'without', 'difference', 'indexOf', 'shuffle',
'lastIndexOf', 'isEmpty', 'chain'];
// Mix in each Underscore method as a proxy to `Collection#models`.
_.each(methods, function(method) {
Collection .prototype[method] = function() {
var args = slice.call(arguments);
args.unshift(this.models);
args.unshift(this.models);
return _fod ;
}; });
又有,把 _.keys / _.values / _.pairs / _.invert / _.pick 等物件操作的實用方法拷貝了 Backbone.Model上 (1.0新增)
var modelMethods = ['keys', 'values', 'pairs', 'invert', 'pick', 'omit'];
// Mix in each Underscore method as a proxy to `Model#attributes`.
_.each(modelMethods, function (method) {
Model.prototype[method] = function() {
var args = slice.call(arguments);
args.unshift(this.attributs); ].apply(_, args);
};
});