2017-05-03 15:35:00 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
|
|
|
|
2017-05-24 15:10:37 +02:00
|
|
|
exports.default = function (fn /*, ...args*/) {
|
|
|
|
var args = (0, _slice2.default)(arguments, 1);
|
|
|
|
return function () /*callArgs*/{
|
|
|
|
var callArgs = (0, _slice2.default)(arguments);
|
|
|
|
return fn.apply(null, args.concat(callArgs));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var _slice = require('./internal/slice');
|
2017-05-03 15:35:00 +02:00
|
|
|
|
2017-05-24 15:10:37 +02:00
|
|
|
var _slice2 = _interopRequireDefault(_slice);
|
2017-05-03 15:35:00 +02:00
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
2017-05-24 15:10:37 +02:00
|
|
|
;
|
|
|
|
|
2017-05-03 15:35:00 +02:00
|
|
|
/**
|
|
|
|
* Creates a continuation function with some arguments already applied.
|
|
|
|
*
|
|
|
|
* Useful as a shorthand when combined with other control flow functions. Any
|
|
|
|
* arguments passed to the returned function are added to the arguments
|
|
|
|
* originally passed to apply.
|
|
|
|
*
|
|
|
|
* @name apply
|
|
|
|
* @static
|
|
|
|
* @memberOf module:Utils
|
|
|
|
* @method
|
|
|
|
* @category Util
|
2017-05-24 15:10:37 +02:00
|
|
|
* @param {Function} fn - The function you want to eventually apply all
|
2017-05-03 15:35:00 +02:00
|
|
|
* arguments to. Invokes with (arguments...).
|
|
|
|
* @param {...*} arguments... - Any number of arguments to automatically apply
|
|
|
|
* when the continuation is called.
|
2017-05-24 15:10:37 +02:00
|
|
|
* @returns {Function} the partially-applied function
|
2017-05-03 15:35:00 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* // using apply
|
|
|
|
* async.parallel([
|
|
|
|
* async.apply(fs.writeFile, 'testfile1', 'test1'),
|
|
|
|
* async.apply(fs.writeFile, 'testfile2', 'test2')
|
|
|
|
* ]);
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* // the same process without using apply
|
|
|
|
* async.parallel([
|
|
|
|
* function(callback) {
|
|
|
|
* fs.writeFile('testfile1', 'test1', callback);
|
|
|
|
* },
|
|
|
|
* function(callback) {
|
|
|
|
* fs.writeFile('testfile2', 'test2', callback);
|
|
|
|
* }
|
|
|
|
* ]);
|
|
|
|
*
|
|
|
|
* // It's possible to pass any number of additional arguments when calling the
|
|
|
|
* // continuation:
|
|
|
|
*
|
|
|
|
* node> var fn = async.apply(sys.puts, 'one');
|
|
|
|
* node> fn('two', 'three');
|
|
|
|
* one
|
|
|
|
* two
|
|
|
|
* three
|
|
|
|
*/
|
|
|
|
module.exports = exports['default'];
|