invoke :: Enumerable |
Since it avoids the cost of a lexical closure over an anonymous function (like you would do with each or collect), this performs much better. Perhaps more importantly, it definitely makes for more concise and more readable source code.
Examples
['hello', 'world', 'cool!'].invoke('toUpperCase') // ['HELLO', 'WORLD', 'COOL!']
['hello', 'world', 'cool!'].invoke('substring', 0, 3) // ['hel', 'wor', 'coo']
// Of course, this works on Prototype extensions (why shouldn't it?!) $('navBar', 'adsBar', 'footer').invoke('hide')
See also
The pluck method does much the same thing for property fetching.
Enumerable: pluck |
Prototype API 1.5.0 - prototypejs.org