Expected identifier, string or number

2019-02-24 11:30发布

问题:

I have an object like;

var defaults = {
        id: 'ActionSlider',
        element: '',
        closeBtnWidth: 55,
        panelWidth: 320,
        class: '',
        css: {},
        create: function() {},
    },

and when i run my page in IE8 standards its giving me the following error;

SCRIPT1028: Expected identifier, string or number

and points to the line : class:' ',

can anyone please tell me why i cant use this for IE? is it a reserved word or something?

回答1:

You need to add quotes round the class which is a reserved word. Please also note, that you should remove the last comma:

var defaults = {
        id: 'ActionSlider',
        element: '',
        closeBtnWidth: 55,
        panelWidth: 320,
        "class": '',
        css: {},
        create: function() {}
    }


回答2:

Yep, class is a reserved word. MDN



回答3:

class is reserved words in javascript



回答4:

Usually class refers to the class attribute of any object like <div >, <input > etc. which shows displays class as <div class="someclass">