可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.