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