Lodash bindKey method
语法
_.bindKey(object, key, [partials])
Creates a function that invokes the method at object[key] with partials prepended to the arguments it receives.
参数
object (Object) − The object to invoke the method on.
key (string) − The key of the method.
[partials] (...*) − The arguments to be partially applied.
输出
(Function) − Returns the new bound function.
实例
var _ = require('lodash');
var object = {
user: 'Joe',
greet: function(message) {
return this.user + ' : ' + message;
}
};
//Bind this with object provided
updateMessage = _.bindKey(object, 'greet', "Welcome");
var result = updateMessage();
console.log(result);
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出