Switch Case not able to use this reference

85 views Asked by At

I have a switch case that I cannot break out of using 'this' if I put a straight forward string it works just fine. I can use this.translation.User anywhere else and it resolves no problem. Any ideas?

switch(test){
   case "User":
      return this.translation.User
      break;
   case "System":
      return this.translation.System
      break;
}
return "";
1

There are 1 answers

0
Travis J On

I believe you have a fundamental misunderstanding of the keyword this.

this is going to refer to the context the code is executing under. this will refer to the window, or global context, unless it is inside of a defined context such as an object, a new function, or event callback.

Make sure you are in the correct context for accessing the translation you are looking for.