Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.bindKey() method of Function in lodash is used to create a function which calls the method at the object[key] along with the partials added to the arguments it accepts.
Note:
- This method is different from the _.bind() method as it permits bound functions to mention methods that may be reinterpreted or does not still exist.
- The _.bindKey.placeholder value that is by default ( _ ) in monolithic builds which is utilized as a placeholder for partially used arguments.
Syntax:
_.bindKey( object, key, partials )
Parameters: This method accepts three parameters as mentioned above and described below:
- object: It is the object which is used to call the method on.
- key: It is the key to be used in the method.
- partials: It is the arguments which is to be partially applied. It is an optional parameter.
Return Value: This method returns the new bound function.
Example 1:
Javascript
// Requiring lodash library const _ = require('lodash'); // Defining object parameter of this method var obj = { 'author': 'Nidhi', 'welcome': function(greet, mark) { return greet + ' ' + this.author + mark; } }; // Using the _.bindKey() method // with its parameters var bound_fun = _.bindKey(obj, 'welcome', 'Hello'); // Calling bound_fun by passing its value bound_fun('!!'); |
Output:
Hello Nidhi!!
Example 2: Using a bound with the placeholder.
Javascript
// Requiring lodash library const _ = require('lodash'); // Defining object parameter of this method var obj = { 'portal': function(portal, mark) { return 'Welcome to ' + portal + mark; } }; // Using the _.bindKey() method with its // parameters and a placeholder var bound_fun = _.bindKey(obj, 'portal', _, '!'); // Calling bound_fun by passing its value bound_fun('GeeksforGeeks'); |
Output:
Welcome to GeeksforGeeks!
Recommended Posts:
- Lodash _.method() Method
- Lodash _.sneq() Method
- Lodash _.toQuery() Method
- Lodash _.uniqWith() Method
- Lodash _.xorWith() Method
- Lodash | _.head() Method
- Lodash | _.remove() Method
- Lodash | _.pullAt() Method
- Lodash | _.pullAll() Method
- Lodash | _.pull() Method
- Lodash | _.nth() Method
- Lodash | _.takeRight() Method
- Lodash | _.take() Method
- Lodash | _.sortedLastIndex() Method
- Lodash | _.fromPairs() Method
- Lodash | _.differenceWith() Method
- Lodash | _.castArray() Method
- Lodash | _.cloneDeep() Method
- Lodash | _.clone() Method
- Lodash | _.sampleSize() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


