invoke

invoke(methodName[, arg...]) -> Array

Invokes the same method, with the same arguments, for all items in a collection. Returns the results of the method calls.

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
$('navBar', 'adsBar', 'footer').invoke('hide')

// because Prototype extensions return the element itself,
// you can also chain 'invoke' calls:
$$('#windows div.close').invoke('addClassName', 'active').invoke('show');

See also

The pluck method does much the same thing for property fetching.