Kurt Z: Vererbungshierarchie ?!?

Beitrag lesen

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

0 67

Vererbungshierarchie ?!?

Kurt Z
  • javascript
  1. 0
    Struppi
    1. 0
      molily
    2. 0
      Don P
      1. 0
        Kurt Z
        1. 0
          Struppi
          1. 0
            Don P
            1. 0
              Struppi
              1. 0
                Don P
                1. 0
                  Struppi
                  1. 0
                    Don P
                    1. 0
                      Struppi
                      1. 0
                        Don P
                        1. 0
                          Struppi
                          1. 0
                            Don P
                      2. 0
                        Kurt Z
                        1. 0
                          Struppi
                          1. 0
                            Kurt Z
                            1. 0
                              Struppi
                              1. 0
                                Kurt Z
                                1. 0
                                  Struppi
                                  1. 0
                                    Kurt Z
                                    1. 0
                                      LanX²
                                    2. 0
                                      Struppi
                                      1. 0
                                        Kurt Z
                                        1. 0
                                          Kurt Z
                                        2. 0
                                          Struppi
                                          1. 0
                                            Kurt Z
                              2. 0
                                Don P
              2. 0
                LanX²
                1. 0

                  Function.prototype.begetObject

                  LanX²
                  1. 0
                    Don P
                    1. 0

                      Knobelaufgabe

                      LanX²
                      1. 0
                        Don P
                    2. 0
                      molily
                      1. 0
                        Kurt Z
                        1. 0

                          Please beget it!

                          LanX²
                          1. 0
                            Kurt Z
                          2. 0
                            Don P
                            1. 0
                              LanX²
                              1. 0
                                Don P
                              2. 0

                                Iterator

                                KurtZ
                                1. 0
                                  LanX
                      2. 0
                        Don P
        2. 0

          new Object(x) statt object(x)

          Kurt Z
          1. 0
            Murphy
            1. 0
              Kurt Z
              1. 0
                Don P
              2. 0
                Murphy
                1. 0
                  Kurt Z
                2. 0
                  molily
  2. 0
    LanX²
  3. 0
    molily
  4. 3

    __proto__ chain

    LanX²
    1. 0
      LanX²
      1. 0
        Kurt Z
    2. 1
      molily
  5. 0

    JS-Version?

    Kurt Z
    1. 0
      Kurt Z
      1. 0
        molily
        1. 0
          molily
    2. 0
      molily
      1. 0
        Kurt Z
        1. 0
          molily
          1. 0
            Kurt Z
  6. 0

    VIELEN DANK!!!

    Kurt Z
    1. 0
      Struppi