Warum javascript binden funktioniert nicht

Funktion:

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);

was ist falsch mit dem binden?

  • Wert hinzufügen, für alle, die nach dieser Frage, dass Sie "one-time" - Bindung durch die Verwendung einer Funktion call oder apply Methode. Also eine andere Lösung für das oben genannte Problem ist zu ersetzen .bind mit .call (hier talk.call(p)).
InformationsquelleAutor Donovant | 2014-04-10
Schreibe einen Kommentar