Lodash _.methodize() Method
Last Updated :
18 Sep, 2020
The Lodash _.methodize() method takes a function and pulls the first argument out of the argument list and into this position. The returned function calls the original with its receiver (this) pre-pending the argument list.
Syntax:
_.methodize( function );
Parameters: This method accepts a single parameter as mentioned above and described below:
- function: original function containing arguments.
Return Value: This method returns a function.
Note: To execute the below examples, you have to install the lodash-contrib library by using this command prompt and execute the following command.
npm install lodash-contrib
Below examples illustrate the Lodash _.methodize() method in JavaScript:
Example 1:
Javascript
var _ = require( 'lodash-contrib' );
function gfgFunc (obj) {
return obj.name + " : " + obj.about;
}
var Geeks = {
name: "GeeksforGeeks" ,
about: "Computer Science Portal for Geeks" ,
fun: _.methodize(gfgFunc)
};
console.log(Geeks.fun())
|
Output:
GeeksforGeeks : Computer Science Portal for Geeks
Example 2:
Javascript
var _ = require( 'lodash-contrib' );
function gfgFunc (obj) {
return "Geeks" ;
}
fun= _.methodize(gfgFunc)
console.log(fun())
|
Output:
Geeks
Share your thoughts in the comments
Please Login to comment...