javascript : why missing name after . operator alert appear

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

why in my script written why missing name after . operator when I've included a script like this

this.switch = function(){       if (this.status == "enabled")       {          this.disable();          this.stop();       }       else       {          this.enable();       }    } 

the script is meant to divert status from enabled to disabled

回答1:

switch is a reserved keyword (for ... switch statements!). If you imperatively, absolutely must use this name, write this['switch'] instead, but it will be annoying to use.

A common name for a function that turns something on/off is toggle().



回答2:

switch is a javascript keyword. Try using a different name for your function.



回答3:

switch is a reserved keyword in JavaScript. You can either use a different name (recommended) or access it a different way:

this['switch'] = function(){ ... }

Recommend you just use a different name though, if you can.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!