
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