Open In App

Lodash _.methodize() Method

Last Updated : 18 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




// Defining lodash contrib variable
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




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
function gfgFunc (obj) {
    return "Geeks";
}
  
fun= _.methodize(gfgFunc)
console.log(fun())


Output:

Geeks


Similar Reads

Underscore.js _.methodize() Method
The _.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) prepending the argument list. Syntax: _.methodize( function ); Parameters: This method accepts a single parameter as mentioned above and described below: function:
1 min read
Lodash _.method() Method
Lodash _.method() method creates a function that invokes the method at the path of a given object. Any additional arguments are provided to the invoked method. Syntax: _.method(path, args);Parameters: path: This is the path to invoke.args: These are the arguments to invoke the method with.Return Value: This method returns the new invoker function.
1 min read
Lodash _.flattenDeep() and _.flattenDepth() Method
Lodash _.flattenDeep() Method The _.flattenDeep() method is used to completely flatten nested arrays. It does this recursively. Syntax: _.flattenDeep( array ) Parameters: This method accepts single parameter as mentioned above and described below: array: This parameter holds the array that to be flatten. Return Value: This method returns the new fl
2 min read
Lodash _.dropWhile() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers etc. The Loadsh.dropWhile() method is used to return the slice of the given array. This takes a predicate function that iterate through each element of the array and if the function returns false, it returned the sli
2 min read
Lodash _.stubFalse() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.stubFalse() method is used to always return a false value. The basic difference between using a normal false value and using the _.stubFalse() method is that lambda functions create a new different functi
1 min read
Lodash _.pullAllBy() Method
The _.pullAllBy() method is used to remove the values from the original array by iterating over each element in the array by using the Iteratee function. It is almost the same as _.pullAll() function. Syntax: _.pullAllBy(array, values, [iteratee=_.identity]) Parameters: This method accepts two parameters as mentioned above and described below: arra
2 min read
Lodash _.sortedLastIndexOf() Method
The _.sortedLastIndexOf method is used to return the highest index of the array where an element can be inserted and maintain its sorted order. Also this method is like _.lastIndexOf except that it performs a binary search on a sorted array.Syntax: _.sortedLastIndexOf(array, value) Parameters: This method accepts two parameters as mentioned above a
1 min read
Lodash _.isSymbol() Method
The _.isSymbol() method is used to find whether the given value is a symbol object or not. It returns True if the given value is a symbol object. Otherwise, it returns false. Syntax: _.isSymbol(value) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter holds the value to check. Return Val
1 min read
Lodash _.toArray() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.toArray() method is used to convert the given value to an array. Syntax: _.toArray( value ) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter
1 min read
Lodash _.reduce() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, objects, numbers etc. The _.reduce() method reduces collection to value which is accumulated result of running each element in the collection through iteratee, where each successive invocation is supplied return value of
2 min read