Search code examples
javascriptinternet-explorercustom-object

Javascript Custom Object - Expected Identifier in IE


I'm new to creating custom object in JavaScript, so it could easily be something simple.

I have these objects:

        function jsonObj(_id,_title,_class,_icon)
        {
            this.attr = new jsonAttrObj(_id,_title,_class);
            this.data = new jsonDataObj(_title,_icon);
            this.children = new Array();
        };

        function jsonAttrObj(_id, _title, _class)
        {
            this.id = _id;
            this.title = _title;
            this.class = _class;
        };

        function jsonDataObj(_title, _icon)
        {
            this.title = _title;
            this.icon = _icon;
        };

I call it using var jsonObject = new jsonObj(id,title,class,icon); all being string vars.

They work fine in Chrome and Firefox, but not IE(8). IE has the error - Expected Identifier.


Solution

  • You cannot use the reserved keyword 'class' as any variable or property name. Funny thing here--this is one of the few places where IE is getting it right and the rest are not.