Sunday, January 25, 2026
HomeLanguagesJavascriptWhat is the usage of Function.prototype.bind in JavaScript ?

What is the usage of Function.prototype.bind in JavaScript ?

Bind method: Using this method, we can bind an object to a common function, so that gives different result when its needed. The bind() method takes an object as an argument and creates a new function. So basically bind function return function.

Let’s understand when bind method is used.

bind the object with common function

Example 1:

Javascript




<script>
    const gfg = {
        name: "javascript",
        content: "prototype",
        feature: function () {
            console.log(
                `Help in learning ${this.name}.
                The topic is ${this.content}`
            );
        }
    }
 
    // Simple method to feature of gfg object
    gfg.feature();
    console.log()
 
    // Try to bind gfg object property feature
    // to other common function so that it
    // used for later use but it does not
    // happen here
    let b = gfg.feature;
    b();
    console.log()
 
    // Now try to bind object using bind
    // method
    // bind method first argument refer
    // object that's why parameter gfg object
    let c = gfg.feature.bind(gfg);
    c();
</script>


Note: Bind different objects to a common function so that each object can access that function and extra functionality to objects so bind function takes any number of arguments.

Example 2: 

Javascript




<script>
    const gfg = {
        name: "javascript",
        content: "prototype",
    }
 
    const gfg1 = {
        name: "c++",
        content: "inheritance",
    }
 
    const gfg2 = {
        name: "java",
        content: "applet",
    }
 
    // Function which is binding with different object
    function features(param) {
        console.log(`Help in learning ${this.name}.
        The topic is ${this.content} and
         these are help in ${param}`)
    }
 
    // Binding obj1 abd extra functionality
    let bindfunc = features.bind(gfg);
 
    bindfunc("placement");
     
    // Binding obj2
    let bindfunc1 = features.bind(gfg2);
    bindfunc1("placement");
</script>


 
 
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
32475 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7221 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS