Search code examples
javascriptbind

Why javascript bind doesn't work


function:

function talk(){ 
        console.log(this.name + " dice: ");
}

var Person = function(name, surname){
    this.name = name;
    this.surname = surname;
}

var p = new Person("Mark", "Red");

talk.bind(p);

what's wrong with bind?


Solution

  • It does work, talk.bind(p) returns the bound function:

    talk.bind(p)();