10

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

3
  • 5
    Maybe because switch is a reserved word Commented Dec 13, 2010 at 14:08
  • Works in chrome though (at least at the console) Commented Dec 13, 2010 at 14:11
  • @Felix: and Firefox (also console). Commented Dec 13, 2010 at 14:13

3 Answers 3

16

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

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.