2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00
Files
axios/lib/helpers/spread.js
T
Jeffrey Horn a130e787c3 return result from callback
returning the result of the callback allows you to chain the promise
like you would expect
2015-09-02 10:43:27 -07:00

28 lines
560 B
JavaScript

'use strict';
/**
* Syntactic sugar for invoking a function and expanding an array for arguments.
*
* Common use case would be to use `Function.prototype.apply`.
*
* ```js
* function f(x, y, z) {}
* var args = [1, 2, 3];
* f.apply(null, args);
* ```
*
* With `spread` this example can be re-written.
*
* ```js
* spread(function(x, y, z) {})([1, 2, 3]);
* ```
*
* @param {Function} callback
* @returns {Function}
*/
module.exports = function spread(callback) {
return function (arr) {
return callback.apply(null, arr);
};
};