Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('array-invoke', function (Y, NAME) {
2
 
3
/**
4
@module collection
5
@submodule array-invoke
6
*/
7
 
8
/**
9
Executes a named method on each item in an array of objects. Items in the array
10
that do not have a function by that name will be skipped.
11
 
12
@example
13
 
14
    Y.Array.invoke(arrayOfDrags, 'plug', Y.Plugin.DDProxy);
15
 
16
@method invoke
17
@param {Array} items Array of objects supporting the named method.
18
@param {String} name the name of the method to execute on each item.
19
@param {Any} [args*] Any number of additional args are passed as parameters to
20
  the execution of the named method.
21
@return {Array} All return values, indexed according to the item index.
22
@static
23
@for Array
24
**/
25
Y.Array.invoke = function(items, name) {
26
    var args = Y.Array(arguments, 2, true),
27
        isFunction = Y.Lang.isFunction,
28
        ret = [];
29
 
30
    Y.Array.each(Y.Array(items), function(item, i) {
31
        if (item && isFunction(item[name])) {
32
            ret[i] = item[name].apply(item, args);
33
        }
34
    });
35
 
36
    return ret;
37
};
38
 
39
 
40
}, '3.18.1', {"requires": ["yui-base"]});