Akorn v0.4.1 Punchlist - "In" not supported by IE

Problem

How it manifests itself

The problem is observable in both Internet Explorer 6.x and Internet Explorer 7.x. It was not tested in Internet Explorer 8.

  • When using Qooxdoo, the framework may add several functions to ARRAY objects to ensure a basic level of functionality. Firefox and Safari already have these functions built in, so Arrays are unaffected in those browsers. The functions that are added in Internet Explorer 6, 7 are:
    • Error.toString()
    • Array.indexOf()
    • Array.lastIndexOf()
    • Array.forEach()
    • Array.filter()
    • Array.map()
    • Array.some()
    • Array.every()
    • String.quote()

When these functions are added, they are added as properties on the Array object.

  • If you use the code structure:
for (var x in obj) {
  alert(obj[x]);
}
  • on a Javascript object with the intent to cycle through the properties for the object, this will work in all browsers.
  • on a Javascript Array in Firefox or Safari, this will work properly.
  • on a Javascript Array in Internet Explorer, you will get an additional 7 values as the loop goes through the array elements AND the added properties.

Solution

If you are looping through a list of properties in a JSON object, in all browsers you must use:

for (var x in obj) {
  alert(obj[x]);
}

If you are looping through an ARRAY or a MAP in a JSON object, you must use either:

for (var i=0;i<arr.length;i++) {
  alert(arr[i]);
}

(This mode works properly in all browsers, as it only loops through the numbered elements, not the added properties.)

Or you must use:

arr.forEach(function(obj) {
  alert(obj);
});

(IMPORTANT NOTE: Using forEach will change the context of 'this' within the function, so be careful when referring to 'this' inside of a forEach loop.)

Yummy Delicious Digg It Facebook Linked In Stumple Upon It Tweet Technorati Reddit Furl
Icons by dryicons