主题
rest
js
_.rest(func, [start=func.length-1])
创建一个函数,使用创建函数的 this
绑定和以数组形式提供的 start
及以后的参数调用 func
。
¥Creates a function that invokes func
with the this
binding of the created function and arguments from start
and beyond provided as an array.
注意:此方法基于 rest 参数。
¥Note: This method is based on the rest parameter.
新增于
¥Since
4.0.0
参数
¥Arguments
func
(函数):应用 rest 参数的函数。¥
func
(Function): The function to apply a rest parameter to.[start=func.length-1]
(数值):其余参数的起始位置。¥
[start=func.length-1]
(number): The start position of the rest parameter.
返回
¥Returns
(函数):返回新函数。
¥(Function): Returns the new function.
示例
¥Example
js
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'