View Site News

IE doesn’t like trailing commas

Posted on: Jul 18th 2006 | Posted by: Rolan |

I had this seemingly undetectable bug on one application I made using javascript. It was running fine on Firefox, no errors or warnings. But when my client checked it out the page wasn’t working. I wasn’t able to test it on IE right away since I only have Firefox installed on my office PC (which is running on Linux with no Wine installed). After arriving home, I looked at the page using IE and yes, the app wasn’t working. It took me the whole night to figure out what was going wrong. I forgot what error message IE was giving me. The only thing I remember is that it doesn’t much about the problem. I read the code one more time, checking for any uninitialized variable or something that I might have overlooked. I was doubtful that it was suffering from cross-browser problems, since I relied mainly on Prototype‘s nice collection of thingies that were already tested for cross-browser compatibility.

I loaded my javascript file on my editor (ConTEXT) and began reading the code again. Half-way through the code, I saw a trailing comma inside an object definition. It kinda looked like this:

JavaScript:
  1. someClass.prototype =
  2. {
  3. someFunction: function()
  4. {
  5. // do something
  6. },
  7. anotherFunction: function()
  8. {
  9. // do another thing
  10. },
  11. }

I almost didn’t notice it. If it wasn’t for the big font I’ve set on my editor, I’d be rewriting a large chunk of my app. Hmmm… looks like Firefox is kind to orphan commas.

Filed in: Javascript/Ajax,Reminders |

Trackback URI | Comments RSS

Leave a Reply