Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

apply.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = function (fn /*, ...args*/) {
  6. var args = (0, _slice2.default)(arguments, 1);
  7. return function () /*callArgs*/{
  8. var callArgs = (0, _slice2.default)(arguments);
  9. return fn.apply(null, args.concat(callArgs));
  10. };
  11. };
  12. var _slice = require('./internal/slice');
  13. var _slice2 = _interopRequireDefault(_slice);
  14. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15. ;
  16. /**
  17. * Creates a continuation function with some arguments already applied.
  18. *
  19. * Useful as a shorthand when combined with other control flow functions. Any
  20. * arguments passed to the returned function are added to the arguments
  21. * originally passed to apply.
  22. *
  23. * @name apply
  24. * @static
  25. * @memberOf module:Utils
  26. * @method
  27. * @category Util
  28. * @param {Function} fn - The function you want to eventually apply all
  29. * arguments to. Invokes with (arguments...).
  30. * @param {...*} arguments... - Any number of arguments to automatically apply
  31. * when the continuation is called.
  32. * @returns {Function} the partially-applied function
  33. * @example
  34. *
  35. * // using apply
  36. * async.parallel([
  37. * async.apply(fs.writeFile, 'testfile1', 'test1'),
  38. * async.apply(fs.writeFile, 'testfile2', 'test2')
  39. * ]);
  40. *
  41. *
  42. * // the same process without using apply
  43. * async.parallel([
  44. * function(callback) {
  45. * fs.writeFile('testfile1', 'test1', callback);
  46. * },
  47. * function(callback) {
  48. * fs.writeFile('testfile2', 'test2', callback);
  49. * }
  50. * ]);
  51. *
  52. * // It's possible to pass any number of additional arguments when calling the
  53. * // continuation:
  54. *
  55. * node> var fn = async.apply(sys.puts, 'one');
  56. * node> fn('two', 'three');
  57. * one
  58. * two
  59. * three
  60. */
  61. module.exports = exports['default'];