Friday, January 30, 2026
HomeLanguagesJavascriptUnderscore.js _.methodize() Method

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: original function containing arguments.

Return Value: This method returns a function.

Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed. 

underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1:

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
function gfgFunc (obj) {
    return obj.name + ": " + obj.about;
}
  
var Geeks = {
    name: "neveropen",
    about: "Computer Science Portal for Geeks",
    fun: _.methodize(gfgFunc)
};
  
console.log(Geeks.fun())


Output:

neveropen: Computer Science Portal for Geeks

Example 2: 

Javascript




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


Output:

Geeks
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6917 POSTS0 COMMENTS