spread source npm

_.spread(func)

创建一个调用 func 的函数。 this 绑定到这个函数上。 把参数作为数组传入,类似于 Function#apply

注意: 这个方法基于 spread operator

参数

  1. func (Function)

    要应用的函数

返回值 (Function)

返回新的函数

示例

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;
}));
// => 返回 76