Friday, October 3, 2025
HomeLanguagesJavascriptUnderscore.js _.bind() Function

Underscore.js _.bind() Function

The _.bind() function is used to bind a function to an object. When the function is called, the value of this will be the object.

Syntax:

_.bind(function, object, *arguments)

Parameters: This function accepts three parameters as mentioned above and described below:

  • function: This parameter holds the function that need to be executed.
  • object: This parameter holds the object elements.
  • arguments: This parameter needs to add some symbols between the elements.

Return Value: It returns the value that bind a function to an object.

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        var fun = function (Geeks) {
            return 'Company Name : ' + this.Company
                + '\nAddress : ' + this.Address
                + '\nContact : ' + this.Contact
        };
  
        fun = _.bind(fun, {
            Company: 'neveropen',
            Address: 'Noida',
            Contact: '+91 9876543210'
        });
  
        console.log(fun());
    </script>
</body>
  
</html>


Output:

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
        var obj = {
            Name: "neveropen",
            Address: "Noida"
        };
  
        var fun = function (Geeks) {
            return 'Welcome to ' + this.Name
                + '\nAddress: ' + this.Address
        };
  
        fun = _.bind(fun, obj);
  
        console.log(fun());
    </script>
</body>
  
</html>


Output:

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

Most Popular

Dominic
32332 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11868 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6819 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS