Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript : why missing name after . operator alert appear

Tags:

javascript

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

like image 236
user495688 Avatar asked Dec 13 '10 14:12

user495688


2 Answers

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().

like image 199
Victor Nicollet Avatar answered Oct 12 '22 22:10

Victor Nicollet


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

like image 41
Spiny Norman Avatar answered Oct 12 '22 23:10

Spiny Norman