Safari’s strictness

Apple’s Safari browser is pretty strict when it comes to certain things in JavaScript. For starters the ECMAScript set of future reserved words are already reserved words in SafariScript. Things like “super” or “export” or “static” are no-go.

Second, I just found this oddity. I’d written some code like this:

var q = document.getElementById('foo').childNodes;
for (var i in q)
    var el = q[i];
    // do stuff with el

This code ran great in Firefox and IE, but on Safari el was never valid. The reason seems to be that Safari really expects a variable given in an array subscript to be a number, not a string (when you use for (foo in bar) foo will be a string).


No replies to “Safari’s strictness”