Syntax Of Lodash rest method
_.rest(func, [start=func.length-1])
The Lodash rest method creates a function that invokes func with the binding of the created function and arguments from start and beyond provided as an array.
Arguments
- func (Function) − The function to apply a rest parameter to.
- [start=func.length-1] (number) − The start position of the rest parameter.
Output
- (Function) − Returns the new function.
Example
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
Output
Hello Joe, Tom & Julie
Next Topic – Click Here