Open In App
Related Articles

Lodash _.bind() Method

Improve Article
Save Article
Like Article

Lodash _.bind() method is used to create a function that will invoke the given function with the this binding of thisArg and it is used to bind a function to an object. When the function is called, the value of this will be the object. The _.bind.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for partially applied arguments.


_.bind(func, thisArg, partials)


This method accepts three parameters as mentioned above and described below:

  • func: This parameter holds the function that will bind.
  • thisArg: This parameter holds the object elements.
  • partials: This parameter needs to add some symbols between the elements.

Return value:

This method returns a new bound function.

Example 1: In this example, the code uses the Lodash library to bind a function to a specific context and then calls the bound function to display company information.


// Acquiring lodash variable
const _ = require('lodash');
// Function
let fun = function (Geeks) {
    return 'Company Name : ' + this.Company
        + '\nAddress : ' + this.Address
        + '\nContact : ' + this.Contact
// Use of bind() function
let func = _.bind(fun, {
    Company: 'GeeksforGeeks',
    Address: 'Noida',
    Contact: '+91 9876543210'


Company Name : GeeksforGeeks 
Address : Noida
Contact : +91 9876543210

Example 2: In this example, the code demonstrates Lodash’s _.bind for function context binding and displays a welcome message with company details in the console.


// Lodash variable
const _ = require('lodash');
let obj = {
    Name: "GeeksforGeeks",
    Address: "Noida"
let fun = function (Geeks) {
    return 'Welcome to ' + this.Name
        + '\nAddress: ' + this.Address
let func = _.bind(fun, obj);


Welcome to GeeksforGeeks 
Address: Noida


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!

Last Updated : 09 Nov, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials