Mankz’s Blog

Trying to combine Ext Core and JQuery idTabs extension

Posted in Uncategorized by Mats Bryntse on May 23, 2009

Don’t ask me why but I was playing around with Ext Core and JQuery idTabs when I had some weird errors. I kept getting errors inside the Ext Core array “remove” augmentation.

Ext.applyIf(Array.prototype, {

    indexOf : function(o){
       for (var i = 0, len = this.length; i < len; i++){
           if(this[i] == o) return i;
       }
       return -1;
    },

    remove : function(o){
       var index = this.indexOf(o);
       if(index != -1){
           this.splice(index, 1);
       }
       return this;
    }
});</code>

I couldn’t understand why I ended up there until I had a look at the idTabs code below (aList is an array).

for(i in aList) $(aList[i]).removeClass(s.selected);

Here’s the culprit: Iterating an array using for in. A better way to do it would be to use a for loop, or to check hasOwnProperty for each property. This way you’re protected if an external framework should augment the native Array object. I prefer using for loops when iterating over arrays.

Tagged with: , ,