explode into code

IE Javascript Application Caveats

Posted in JS, Tips by jonursenbach on July 18, 2009

The one and only thing that I despise with web development is having to deal with Internet Explorer. Aside from having to deal with the regular unsupported CSS bullshit, even worse is writing dynamic applications with Javascript. Generally if you are using a popular JS framework (jQuery, Prototype, MooTools), you shouldn’t have to worry too much about cross-browser issues as the people running those teams have done all of the hard work for you. However, there are those few, but rare, moments where you come across an instance of IE implementing proper standards. The following are some of the more common cases that I’ve come across lately while reviewing code.

objectName.delete();

One of the few times where IE actually conforms to the EMCAScript standards is that you absolutely cannot have a function named “delete”. This will work in Firefox, Safari and Chrome (as far as I am aware at least), but will render an undecipherable error when loaded in IE.

dontForgetYour;

No butts about it, all statements must end with a semicolon.

Give me 20 CCs of comma, stat!

When working with JSON objects and arrays, leaving trailing commas at the end of your arrays are going to give you a bad time. Example:

var jsonObj;
jsonObj = {‘first’, ‘second’, ‘third’, ‘fourth’,};

Have fun tracking down that bug in a couple thousand line application!

Var? What var?

All variables that you’re using in functions, objects or classes must be declared with a proper var declaration. Forgetting to do this will sometimes cause your application to do some funky shit, but not always I’ve found. The randomness of bugs like this happening, though, are rare enough to deal with.

So what can I do?

Well the best thing you can do, since IE is notioriously difficult to debug JS applications is to properly lint your code with Douglas Crockford’s JSLint (http://jslint.com). If you’re a PHP developer, or adept at running PHP CLI scripts, soon you will be able to use my JSLint-PHP program (http://code.google.com/p/jslint-php).

Lastly, you can also install Firebug Lite (http://getfirebug.com/lite.html) so you have access to the standard Firebug console, allowing you to run things like console.log().

Hope this helps, and if you have any more tips please add them in the comments.

Follow

Get every new post delivered to your Inbox.