/*
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 3.2.0
build: 2676
*/
YUI.add('array-invoke', function(Y) {
/**
* Collection utilities beyond what is provided in the YUI core
* @module collection
* @submodule array-invoke
*/
/**
* Adds the Y.Array.invoke( items, methodName )
utility method.
* @class YUI~array~invoke
*/
/**
*
Execute a named method on an array of objects. Items in the list that do
* not have a function by that name will be skipped. For example,
* Y.Array.invoke( arrayOfDrags, 'plug', Y.Plugin.DDProxy );
The return values from each call are returned in an array.
* * @method invoke * @static * @param items { Array } Array of objects supporting the named method * @param name { String } the name of the method to execute on each item * @param args* { mixed } Any number of additional args are passed as * parameters to the execution of the named method. * @return { Array } All return values, indexed according to item index. */ Y.Array.invoke = function ( items, name ) { var args = Y.Array( arguments, 2, true ), isFunction = Y.Lang.isFunction, ret = []; Y.Array.each( Y.Array( items ), function ( item, i ) { if ( isFunction( item[ name ] ) ) { ret[i] = item[ name ].apply( item, args ); } }); return ret; }; }, '3.2.0' );