rest source npm

_.rest(func, [start=func.length-1])

创建一个调用 func 的函数。 this 绑定到这个函数 并且 从 start 之后的参数都作为数组传入。

注意: 这个方法基于rest parameter

参数

  1. func (Function)

    要应用的函数

  2. [start=func.length-1] (number)

    从第几个参数开始应用

返回值 (Function)

返回新的函数

示例

var say = _.rest(function(what, names) {
  return what + ' ' + _.initial(names).join(', ') +
    (_.size(names) > 1 ? ', & ' : '') + _.last(names);
});

say('hello', 'fred', 'barney', 'pebbles');
// => 'hello fred, barney, & pebbles'