Tuesday, August 03, 2010

Aptana IE quirk

I'm working on a small application using Aptana Studio 2.0.5.

There's an html page which imports a Javascript file near the top. I decided to reorganize my Javascript file, and blam! the page stopped working in Aptana's "IE" view (the tab that appears next to the "Source" view). I checked out the page in Firefox 3.6.8, and it worked fine. Then I checked it outside of Aptana, in IE 8, and it worked fine there too!

Aptana's IE view is not a necessity but it is kind of handy. So I wanted it working again. Plus the fact that it wasn't working might mean there's an issue in other browsers.

By trimming the Javascript file and throwing in a couple of alerts, I figured out the problem: an extra comma. My original Javascript file ended like this:

manager = {
xMax : 12,
yMax : 12,
}

It was the trailing comma that killed the script in Aptana; once I removed that the page worked fine again. Do you want to play "spot the Java programmer"? In Java, trailing commas are allowed in arrays, and I sometimes use them when coding in Java.

So: are trailing commas forbidden in Javascript arrays? Way back in December of 2009 (practically prehistory), Amaxus said:
The most common IE problem we encounter is trailing commas in arrays. It doesn’t cause problems with Firefox, but it’s syntactically invalid and crashes IE.
That discussion was about IE 7, and apparently IE 8 is more lenient. However, the JSLint page says that trailing commas are a no-no in Javascript, also. I should probably run my Javascript through JSLint at some point.

Labels: , , ,

0 Comments:

Post a Comment

<< Home