Here's an interesting solution how to add all methods of underscore.js
to native types
// Underscore methods that we want to implement on Array.
var methods = ['each', 'map', 'reduce', 'reduceRight', 'detect',
'select',
'reject', 'all', 'any', 'include', 'invoke', 'pluck', 'max',
'min', 'sortBy',
'sortedIndex', 'toArray', 'size', 'first', 'rest', 'last',
'without',
'indexOf', 'lastIndexOf', 'isEmpty'];
// Mix in each method as a proxy.
_.each(methods, function(method) {
Array.prototype[method] = function() {
return _[method].apply(_, [this].concat(_.toArray(arguments)));
};
});
full thread is here http://github.com/documentcloud/underscore/issues/38