invoke :: Enumerable

invoke(methodName[, arg...]) -> Array Optimization for a common use-case of each or collect: invoking the same method, with the same potential arguments, for all the elements. Returns the results of the method calls.

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