Der instanceof
Operator am Prototyp aussehen sollte, nicht wahr? Warum ändert sich die Antwort nicht, nachdem der Prototyp des Objekts geändert wurde? Beispiel unten:warum instanceof immer wahr sagt, nachdem der Prototyp geändert wurde?
// The .prototype of objects created with 'new MyKlass'
// is MyKlass.prototype
var MyKlass = function(name, age) {
this.name = name;
this.age = age;
}
var xx = new MyKlass('xx', 20);
console.log(xx instanceof MyKlass); // true, OK
xx.prototype = new String('s');
console.log(xx instanceof MyKlass); // also true, WHY???
zum internen [] [Prototyp] Schreiben Warum kann 'prototype' von' MyKlass' ändern, aber nicht 'xx.prototype'? Arent sowohl "MyKlass" und "xx" Objekte? – zpzp
was meinst du stumm? Kannst du etwas klarer erklären? –
@OliverWatkins ein Objekt zu mutieren, ist der allgemeine Betrieb seine Klasse zu ändern. Die meisten OOP- (oder POOP-) Sprachen lassen das nicht zu, weil es unordentlich ist. –