主题
spread
js
_.spread(func, [start=0])创建一个函数,使用创建函数的 this 绑定和与 Function#apply 非常相似的参数数组调用 func。
¥Creates a function that invokes func with the this binding of the create function and an array of arguments much like Function#apply.
注意:此方法基于 扩展运算符。
¥Note: This method is based on the spread operator.
新增于
¥Since
3.2.0
参数
¥Arguments
func(函数):分散参数的函数。¥
func(Function): The function to spread arguments over.[start=0](数值):扩展的起始位置。¥
[start=0](number): The start position of the spread.
返回
¥Returns
(函数):返回新函数。
¥(Function): Returns the new function.
示例
¥Example
js
var say = _.spread(function(who, what) {
return who + ' says ' + what;
});
say(['fred', 'hello']);
// => 'fred says hello'
var numbers = Promise.all([
Promise.resolve(40),
Promise.resolve(36)
]);
numbers.then(_.spread(function(x, y) {
return x + y;
}));
// => a Promise of 76