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

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to