API Docs for: 3.10.3
Show:

File: collection/js/invoke.js

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