invoke.js 512 B

1234567891011121314151617181920212223
  1. var slice = require('./slice');
  2. /**
  3. * Call `methodName` on each item of the array passing custom arguments if
  4. * needed.
  5. */
  6. function invoke(arr, methodName, var_args){
  7. if (arr == null) {
  8. return arr;
  9. }
  10. var args = slice(arguments, 2);
  11. var i = -1, len = arr.length, value;
  12. while (++i < len) {
  13. value = arr[i];
  14. value[methodName].apply(value, args);
  15. }
  16. return arr;
  17. }
  18. module.exports = invoke;