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