1 /** Used as the `TypeError` message for "Functions" methods. */
2 var FUNC_ERROR_TEXT = 'Expected a function';
5 * Creates a function that invokes `func` with the `this` binding of the created
6 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
8 * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/Web/JavaScript/Reference/Operators/Spread_operator).
13 * @param {Function} func The function to spread arguments over.
14 * @returns {Function} Returns the new function.
17 * var say = _.spread(function(who, what) {
18 * return who + ' says ' + what;
21 * say(['fred', 'hello']);
22 * // => 'fred says hello'
25 * var numbers = Promise.all([
26 * Promise.resolve(40),
30 * numbers.then(_.spread(function(x, y) {
33 * // => a Promise of 76
35 function spread(func) {
36 if (typeof func != 'function') {
37 throw new TypeError(FUNC_ERROR_TEXT);
39 return function(array) {
40 return func.apply(this, array);
44 module.exports = spread;