Internet Explorer never ceases to frustrate me. I have been writing my own JavaScript library, mostly to sharpen my skills. I was moving along and had written a large portion of code, easy OOP classes, a few utility functions, and my HtmlElement extensions. Problem was I had only been testing the code in Firefox.
At this point I desided to run it through Internet Explorer just to verify that it worked. This is where I stayed for about 30 minutes. No matter what I did I could not get things to run in IE. It kept throwing a useless error, ‘Object expected’, that didn’t seem to relate to anything.
As it turns out IE has a couple of instances you cannot use.
First off you cannot use the word class in any way, shape, or form. It doesn’t matter if it is a method or property of an Object, you just can’t use it.
Secondly, you cannot have a method or propery of an Object named extends.
These apply to all lowercase letters only. If you try this IE will throw errors all day long while every other browser in the world will gladly accept it and run fine. I should have guessed when I saw that Mootools was using Class and Extends but then again it is just impossible to guess what kind of mess is under the hood of IE.
If you are wondering this is not fixed in IE8 beta 2 either…probably never will be. My guess is that they are used internally somehow so you are blocked from using them.
Hopefully my 30 minutes of frustration will save you from running into this problem.
//what doesn't work
var class = function() { };
var obj = { extends: function() { } };
//what works
var Class = function() { };
var obj = { Extends: function() { } };
Did You Enjoy This Post?
Be sure to grab my RSS feed so you don't miss out on more great articles.
This Post Was Brought To You By
How do I save time? I use FreshBooks for invoicing.
Get Information Technology magazine subscriptions and white papers for FREE!
Why Must Internet Explorer Torture Me?

Did you like this post? Be sure to

October 9th, 2008 at 11:21 am
This is not a bug. class and extends are reserved keywords in the Microsoft(Ecmascript) standard. See FutureReservedWord in ECMA-262.
Microsoft supports two dialects of Javascript called JScript and JScript.NET. Your problem is a result of this.
October 9th, 2008 at 6:06 pm
Thanks Jan, I doubted it was a bug and that it was the case of reserved words. I just wish they could support the same javascript as everybody else.