Lodash – bindKey method

  • Post author:
  • Post category:Lodash
  • Post comments:1 Comment
Lodash - bindKey method

Syntax Of Lodash bindKey method

_.bindKey(object, key, [partials])

Lodash bindkey method creates a function that invokes the method at an object[key] with partials prepended to the arguments it receives.

Arguments

  • object (Object) − The object to invoke the method on.
  • key (string) − The key of the method.
  • [partials] (…*) − The arguments to be partially applied.

Output

  • (Function) − Returns the new bound function.

Example

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

Output

Joe : Welcome

Next Topic – Click Here

This Post Has One Comment

Leave a Reply