Lodash bind method
语法
_.bind(func, thisArg, [partials])
Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.
参数
func (Function) − The function to bind.
thisArg (*) − The this binding of func.
[partials] (...*) − The arguments to be partially applied.
输出
(Function) − Returns the new bound function.
实例
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
输出