I wrote some JavaScript on Chrome and then tried to run it in IE8. The first thing I ran into was the lack of Array.map, Array.filter and all their useful cousins. To get around this, I added some of the shims found here.
This broke all my for ... in ... loops, like this:
>> c = [1];
{...}
>> for(i in c) { console.log(i);}
LOG: 1
LOG: indexOf
LOG: lastIndexOf
LOG: filter
I would want that to iterate over array entries only. Is there a way around this or do I need to go back to writing for(i=0;i<c.length;++i) loops?
You need to sanitize your loops, using
hasOwnPropertythe shim adds functionality to the array prototype and you end up looping over the added functions.References:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
http://msdn.microsoft.com/en-us/library/328kyd6z(v=vs.94).aspx
Crockford on
for .. inhttp://javascript.crockford.com/code.html search for “hasOwnProperty”