~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.13.0/array-invoke/array-invoke.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

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