]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/collection/array-invoke.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / collection / array-invoke.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('array-invoke', function(Y) {
9
10 /**
11  * Collection utilities beyond what is provided in the YUI core
12  * @module collection
13  * @submodule array-invoke
14  */
15
16 /**
17  * Adds the <code>Y.Array.invoke( items, methodName )</code> utility method.
18  * @class YUI~array~invoke
19  */
20
21 /**
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>
25  *
26  * <p>The return values from each call are returned in an array.</p>
27  *
28  * @method invoke
29  * @static
30  * @param { Array } items Array of objects supporting the named method.
31  * @param { String } name the name of the method to execute on each item.
32  * @param { mixed } args* 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.
35  */
36 Y.Array.invoke = function(items, name) {
37     var args = Y.Array(arguments, 2, true),
38         isFunction = Y.Lang.isFunction,
39         ret = [];
40
41     Y.Array.each(Y.Array(items), function(item, i) {
42         if (isFunction(item[name])) {
43             ret[i] = item[name].apply(item, args);
44         }
45     });
46
47     return ret;
48 };
49
50
51 }, '3.3.0' );