Search code examples
javascriptprototypejs

"class is a reserved identifier" what is wrong in my javascript


I am try using prototype javascript framework. i have next code

CheckBoxSlider = Class.create({
    initialize: function (checkbox, block) {
        this.checkbox= $(checkbox);
        this.block=$(block);
        this.checkbox.observe("click", this.onClick.bind(this));
    },
    onClick: function (event) {
        alert("Hello"); 
    }
});
window.onload= function() {
   tmp = new CheckBoxSlider("register-new-user","regiser-new-user-fields");
};

But on click after alert i got error "class is a reserved identifier" What is wrong?

Sorry it's my mistake. The script works fine, the problem was in html


Solution

  • Could it be that you forgot to load the prototype scripting, or loaded the prototype script after your own scripting? Your snippet is working in this jsfiddle