Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/axios/lib/helpers/spread.js
1126 views
1
'use strict';
2
3
/**
4
* Syntactic sugar for invoking a function and expanding an array for arguments.
5
*
6
* Common use case would be to use `Function.prototype.apply`.
7
*
8
* ```js
9
* function f(x, y, z) {}
10
* var args = [1, 2, 3];
11
* f.apply(null, args);
12
* ```
13
*
14
* With `spread` this example can be re-written.
15
*
16
* ```js
17
* spread(function(x, y, z) {})([1, 2, 3]);
18
* ```
19
*
20
* @param {Function} callback
21
* @returns {Function}
22
*/
23
module.exports = function spread(callback) {
24
return function wrap(arr) {
25
return callback.apply(null, arr);
26
};
27
};
28
29