Alexey Petrushin
2011-Jul-22 17:13 UTC
Re: Rails JS best practices? (jQuery + Prototype / MooTools
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.