1 var apply = require('./internal/apply');
3 /** Used as the `TypeError` message for "Functions" methods. */
4 var FUNC_ERROR_TEXT = 'Expected a function';
7 * Creates a function that invokes `func` with the `this` binding of the created
8 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
10 * **Note:** This method is based on the [spread operator](https://mdn.io/spread_operator).
15 * @param {Function} func The function to spread arguments over.
16 * @returns {Function} Returns the new function.
19 * var say = _.spread(function(who, what) {
20 * return who + ' says ' + what;
23 * say(['fred', 'hello']);
24 * // => 'fred says hello'
27 * var numbers = Promise.all([
28 * Promise.resolve(40),
32 * numbers.then(_.spread(function(x, y) {
35 * // => a Promise of 76
37 function spread(func) {
38 if (typeof func != 'function') {
39 throw new TypeError(FUNC_ERROR_TEXT);
41 return function(array) {
42 return apply(func, this, array);
46 module.exports = spread;