Lodash教程

Lodash rest method

语法

_.rest(func, [start=func.length-1])
Creates a function that invokes func with the this binding of the created function and arguments from start and beyond provided as an array.

参数

func (Function) − The function to apply a rest parameter to. [start=func.length-1] (number) − The start position of the rest parameter.

输出

(Function) − Returns the new function.

实例

var _ = require('lodash');
var say = _.rest(function(what, names) {
   return what + ' ' + _.initial(names).join(', ') + (_.size(names) > 1 ? ' & ' : '') + _.last(names);
});
console.log(say('Hello', 'Joe', 'Tom', 'Julie'));
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

Hello Joe, Tom & Julie
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4