Ich verfolge die Hinweise auf ES6 von diesem link und erstellt einen kleinen Code-Schnipsel zum Spielen.Javascript Prototyp Funktion zurück NAN
class Bar{
constructor(x,y){
this.x = x;
this.y = y;
}
}
let bar = new Bar(12,10);
Bar.prototype.foo =function(){
return this.x + this.y;
}
bar.foo() // 22 correct
Ich bin so glücklich, bis ich das mache.
let baz = bar.foo
baz(); // NaN
Warum baz() druckt NaN?
Weil 'baz()' die Funktion nicht rufen 'bar' (oder ein beliebiges Objekt mit 'X' und 'Y' Eigenschaften) – Bergi
Bitte empfehlen Sie mir jede Änderung auf Frage Text. Es sieht wie zu generisch aus –
Mögliches Duplikat von [Wie funktioniert das "dieses" Schlüsselwort?] (Https://stackoverflow.com/q/3127429/218196) –