
Syntax Of Lodash bind method
_.bind(func, thisArg, [partials])
The Lodash bind method creates a function that invokes func with this binding of thisArg and partials prepended to the arguments it receives.
Arguments
- func (Function) − The function to bind.
- thisArg (*) − The this binding of func.
- [partials] (…*) − The arguments to be partially applied.
Output
- (Function) − Returns the new bound function.
Example
var _ = require('lodash'); var updateMessage = function(message) { return this.name + ' : ' + message; } //Bind this with object provided updateMessage = _.bind(updateMessage, {name: 'BinderObject'}, "Welcome"); var result = updateMessage(); console.log(result);
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
BinderObject : Welcome
Next Topic – Click Here
Pingback: Lodash - before method - Adglob Infosystem Pvt Ltd