Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / spread.js
1 var apply = require('./internal/apply');
2
3 /** Used as the `TypeError` message for "Functions" methods. */
4 var FUNC_ERROR_TEXT = 'Expected a function';
5
6 /**
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).
9  *
10  * **Note:** This method is based on the [spread operator](https://mdn.io/spread_operator).
11  *
12  * @static
13  * @memberOf _
14  * @category Function
15  * @param {Function} func The function to spread arguments over.
16  * @returns {Function} Returns the new function.
17  * @example
18  *
19  * var say = _.spread(function(who, what) {
20  *   return who + ' says ' + what;
21  * });
22  *
23  * say(['fred', 'hello']);
24  * // => 'fred says hello'
25  *
26  * // with a Promise
27  * var numbers = Promise.all([
28  *   Promise.resolve(40),
29  *   Promise.resolve(36)
30  * ]);
31  *
32  * numbers.then(_.spread(function(x, y) {
33  *   return x + y;
34  * }));
35  * // => a Promise of 76
36  */
37 function spread(func) {
38   if (typeof func != 'function') {
39     throw new TypeError(FUNC_ERROR_TEXT);
40   }
41   return function(array) {
42     return apply(func, this, array);
43   };
44 }
45
46 module.exports = spread;