MDL-32843 import YUI 3.5.1
[moodle.git] / lib / yui / 3.5.1 / build / array-invoke / array-invoke.js
blobd8af40d899bdf5f81dd8e462abd8f2c544ed4246
1 /*
2 YUI 3.5.1 (build 22)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('array-invoke', function(Y) {
9 /**
10 @module collection
11 @submodule array-invoke
14 /**
15 Executes a named method on each item in an array of objects. Items in the array
16 that do not have a function by that name will be skipped.
18 @example
20     Y.Array.invoke(arrayOfDrags, 'plug', Y.Plugin.DDProxy);
22 @method invoke
23 @param {Array} items Array of objects supporting the named method.
24 @param {String} name the name of the method to execute on each item.
25 @param {Any} [args*] Any number of additional args are passed as parameters to
26   the execution of the named method.
27 @return {Array} All return values, indexed according to the item index.
28 @static
29 @for Array
30 **/
31 Y.Array.invoke = function(items, name) {
32     var args = Y.Array(arguments, 2, true),
33         isFunction = Y.Lang.isFunction,
34         ret = [];
36     Y.Array.each(Y.Array(items), function(item, i) {
37         if (item && isFunction(item[name])) {
38             ret[i] = item[name].apply(item, args);
39         }
40     });
42     return ret;
46 }, '3.5.1' ,{requires:['yui-base']});