In Javascript OO, when should I use the this
keyword?
Also, if I want to call a method of a class from another method of the same class, should I use
When it comes to "object-oriented" JavaScript, here's a nice guide Mark Dickinson here on SO linked to: Private Members in JavaScript. It does go into detail about some other stuff you don't really need now, but once you understand how JavaScript works, you'll see that it's quite different from your ordinary object-oriented language when it comes to things like what this
really means.
I'd say that in your case, you should definitely use this
, but maybe your functions should be in the prototype
part of your "class" (this avoids redefining the function every time a new instance is created.)
I have found 3 Ways to define a javascript class helpful.