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>     <scripttype="text/javascript"src=     </script> </head>  Â<body>     <scripttype="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>     <scripttype="text/javascript"src=     </script> </head>  Â<body>     <scripttype="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:


 
                                    








