Open In App

Lodash _.bindKey() Method

Lodash _.bindKey() method of Function in lodash is used to create a function that calls the method at the object[key] along with the partials added to the arguments it accepts.

Note:

Syntax:

_.bindKey(object, key, partials);

Parameters:

Return Value:

This method returns the new bound function.



Example 1: In this example, we are passing partials to the function and printing the result into the console by the use of the lodash _.bindKey() method.




// Requiring lodash library
const _ = require('lodash');
 
// Defining object parameter of this method
let obj = {
    'author': 'Nidhi',
    'welcome': function (greet, mark) {
        return greet + ' ' + this.author + mark;
    }
};
 
// Using the _.bindKey() method
// with its parameters
let bound_fun =
    _.bindKey(obj, 'welcome', 'Hello');
 
// Calling bound_fun by passing its value
console.log(bound_fun('!!'));

Output:



Hello Nidhi!!

Example 2: In this example, we are passing partials to the function and using a bound with the placeholder then printing the result into the console by the use of the lodash _.bindKey() method.




// Requiring lodash library
const _ = require('lodash');
 
// Defining object parameter of this method
let obj = {
    'portal': function (portal, mark) {
        return 'Welcome to ' + portal + mark;
    }
};
 
// Using the _.bindKey() method with its
// parameters and a placeholder
let bound_fun =
    _.bindKey(obj, 'portal', _, '!');
 
// Calling bound_fun by passing its value
console.log(bound_fun('GeeksforGeeks'));

Output:

Welcome to GeeksforGeeks!

Article Tags :