Hi
wie funktioniert eigentlich das prototype-Attribut genau?
kleines Beispiel im FF2:
function class0() {
this.class0 = "SUPER";
}
function class1() {
this.class1 = "SUB";
}
function instance() {
this.instance="EXEMPLAR";
}
class1.prototype = new class0();
instance.prototype = new class1();
delete(obj);
obj = new instance();
out=obj.constructor+"\n";
for(attr in obj) {
out+=attr+": "+obj[attr]+"\n";
}
alert(out);
gibt mir brav die komplette vererbungskette aus:
function class0() { this.class0 = "SUPER"; }
instance: EXEMPLAR
class1: SUB
class0: SUPER
vertausche ich aber die prototype-Anweisungen
instance.prototype = new class1();
class1.prototype = new class0();
bekomme ich nur:
function class1() { this.class1 = "SUB"; }
instance: EXEMPLAR
class1: SUB
Wieso ist die Reihenfolge relevant??? Prototyp wird doch dynamisch ausgewertet...
und wieso ändert sich der constructor???
Ist das jetzt FF spezifisch oder allgemein so dokumentiert?
Kann mir jemand bitte einen guten Link geben wo Vererbungsketten und prototype genau erklärt werden?
Ciao
Kurt