Christoph: "Herrje" Cheatah

Beitrag lesen

Moin.

Aha. Und wie sieht die Implementierung von iterOwn aus, damit das so funktioniert?

Es lässt sich schon irgendwie drehen, dass das so oder so ähnlich funktioniert. Mal ein Beispiel:

  
function iterator(obj) {  
 var i = 0;  
 var props = [];  
  
 for(var prop in obj) {  
  if(obj.hasOwnProperty(prop))  
   props.push(prop);  
 }  
  
 return {  
  next : function() {  
   if(i < props.length) {  
    this.key = props[i];  
    this.value = obj[props[i]];  
    ++i;  
    return true;  
   }  
   else return false;  
  }  
 };  
}  
  
with(iterator(obj)) while(next()) {  
 document.writeln(key + ' : ' + value);  
}  

Das das natürlich totaler Käse ist und wesentlich weniger performant als

  
for(var prop in obj) {  
 if(obj.hasOwnProperty(prop))  
  document.writeln(prop + ' : ' + obj[prop]);  
}  

ist, ist klar ;)

Christoph

0 139

was bewirkt {}

Ric
  • javascript
  1. 0
    Don P
  2. 0
    KurtZ
    1. 0
      Don P
      1. 0
        KurtZ
        1. 0
          Don P
          1. 0
            KurtZ
            1. 0
              Don P
              1. 0
                KurtZ
                1. 0
                  Cheatah
                  1. 0
                    KurtZ
                    1. 0
                      Don P
                      1. 0
                        KurtZ
                        1. 0
                          Siechfred
                    2. 0
                      Cheatah
        2. 0
          Don P
          1. 0
            KurtZ
            1. 0
              Don P
              1. 0
                KurtZ
    2. 0
      Cheatah
      1. 0
        KurtZ
        1. 0
          Siechfred
          1. 0
            KurtZ
            1. 0
              Cheatah
              1. 0
                KurtZ
                1. 1
                  Siechfred
                  1. 0
                    KurtZ
                    1. 0
                      Siechfred
                      1. 0
                        KurtZ
                        1. 0
                          Don P
                      2. 0
                        Siechfred
                      3. 2
                        Daniel Thoma
                        1. 0
                          KurtZ
                        2. 0
                          Siechfred
                          1. 0
                            Daniel Thoma
                            1. 0
                              Struppi
      2. 0

        "Herrje" Cheatah

        KurtZ
        1. 0
          Don P
          1. 0
            KurtZ
            1. 1
              Don P
              1. 0
                KurtZ
                1. 0
                  Don P
                  1. 0
                    KurtZ
        2. 0
          Siechfred
          1. 0
            KurtZ
            1. 0
              KurtZ
              1. 0
                Christoph
                1. 0
                  KurtZ
                  1. 0
                    Christoph
                    1. 0
                      LanX
                      1. 0
                        LanX
                        1. 0
                          Don P
                          1. 0
                            KurtZ
                            1. 0
                              Don P
                      2. 0
                        molily
                        1. 0
                          Christoph
                          1. 0
                            KurtZ
                            1. 0
                              Struppi
                            2. 0
                              Struppi
                            3. 0
                              Christoph
                              1. 0
                                Don P
                              2. 0
                                molily
                                1. 0
                                  molily
                              3. 0

                                "Herrje" Christoph

                                KurtZ
                                1. 0
                                  KurtZ
                                  1. 0
                                    Christoph
                                    1. 0
                                      KurtZ
                                      1. 0
                                        molily
                          2. 0
                            LanX²
                        2. 0
                          LanX²
                          1. 0
                            molily
                            1. 0
                              LanX²
                              1. 0
                                molily
                                1. 0
                                  KurtZ
                                  1. 0
                                    molily
                                    1. 0
                                      KurtZ
                              2. 0
                                KurtZ
                                1. 0
                                  LanX²
                    2. 0
                      molily
                      1. 0
                        LanX
                        1. 0
                          molily
                      2. 0
                        Christoph
            2. 0
              Siechfred
              1. 1

                Lieber SIechfred!

                KurtZ
                1. 0
                  Struppi
                  1. 0
                    Don P
                  2. 0
                    KurtZ
                    1. 0
                      Struppi
                      1. 0
                        KurtZ
                        1. 0
                          Struppi
                          1. 0

                            Lieber Struppi!

                            KurtZ
                          2. 1
                            Christoph
                            1. 0
                              Struppi
                            2. 0

                              Lieber Christof ;)

                              KurtZ
                              1. 0
                                KurtZ
                              2. 1
                                Christoph
                              3. 0

                                Lieber Christo__ph__ ;)

                                Christoph
                                1. 0
                                  KurtZ
                2. 0
                  Siechfred
                  1. 0

                    Lieber Siechfred!

                    KurtZ
                    1. 0
                      molily
                      1. 0
                        KurtZ
                3. 0
                  KurtZ
          2. 0

            Der Hash in Prototype

            Tim Tepaße
        3. 0
          Cheatah
          1. 0
            KurtZ
            1. 0
              Cheatah
      3. 0

        Übrigens, JS hat auch keine Arrays!

        KurtZ
        1. 0
          Don P
        2. 0
          Struppi
          1. 0
            KurtZ
            1. 0
              Struppi
              1. 0
                KurtZ
                1. 0
                  KurtZ
                2. 0
                  Struppi
                  1. 0
                    KurtZ
                    1. 0
                      Struppi
                      1. 0
                        KurtZ
                        1. 0
                          molily
                    2. 1
                      Don P
                      1. 0
                        KurtZ
                      2. 0
                        molily
                  2. 1
                    molily
        3. 2
          molily
        4. 0
          Harlequin
    3. 3
      KurtZ
    4. 0
      Struppi
      1. 0
        KurtZ
        1. 0
          molily
          1. 0
            KurtZ
            1. 0
              Christoph
              1. 0
                KurtZ
                1. 0
                  KurtZ
  3. 0

    Assoziative Arrays - es gibt sie doch!

    Christoph
    1. 0

      leicht modifiziert

      Christoph
      1. 0

        Iteratoren zur Realisierung von »reinen« Hashes nutzen

        Tim Tepaße
        1. 0
          Christoph
          1. 0
            Tim Tepaße
    2. 0
      Struppi