ustaw atrybut za pomocą super metody javascript [duplikat]
Możliwy duplikat:
Dlaczego moje właściwości obiektu JS są nadpisywane przez inne instancje
Dlaczego atrybut „t” nie został zmieniony po wywołaniu setT? Oczekiwałbym „4” jako wyjścia, ale wyświetla „domyślne”.
function Car(i) {
var id = i;
var t = "default";
this.getT = function() { return t; }
this.setT = function(p) {
t = p; // attribute t isn't changed ..
}
}
function ECar(id) {
Car.call(this, id); // super constructor call
this.setT = function(p) { // override
ECar.prototype.setT.call(this, p); // super call
}
}
ECar.prototype = new Car();
ecar = new ECar(3);
ecar.setT(4);
alert(ecar.getT()); // prints default, not 4