2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.com/yui/license.html
8
YUI.add('array-invoke', function(Y) {
11
* Collection utilities beyond what is provided in the YUI core
13
* @submodule array-invoke
17
* Adds the <code>Y.Array.invoke( items, methodName )</code> utility method.
18
* @class YUI~array~invoke
22
* <p>Execute a named method on an array of objects. Items in the list that do
23
* not have a function by that name will be skipped. For example,
24
* <code>Y.Array.invoke( arrayOfDrags, 'plug', Y.Plugin.DDProxy );</code></p>
26
* <p>The return values from each call are returned in an array.</p>
30
* @param items { Array } Array of objects supporting the named method
31
* @param name { String } the name of the method to execute on each item
32
* @param args* { mixed } Any number of additional args are passed as
33
* parameters to the execution of the named method.
34
* @return { Array } All return values, indexed according to item index.
36
Y.Array.invoke = function ( items, name ) {
37
var args = Y.Array( arguments, 2, true ),
38
isFunction = Y.Lang.isFunction,
41
Y.Array.each( Y.Array( items ), function ( item, i ) {
42
if ( isFunction( item[ name ] ) ) {
43
ret[i] = item[ name ].apply( item, args );