Lodash教程

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

\>node tester.js

输出

Joe : Welcome
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4