Using self instead of this


#1

Hi, I see that some users use self instead of this in their code when I watch the videos under scores such as self.attack(“zork”); However, when I try it, I get the error self is undefined. I know that I can define it by var self = this, but in the videos I watched, I did not see that used at all. Just self.attack().

Thanks!


#2

Eureka! Think I solved this mystery myself. I think those other players and even the code examples given under the Goals that first load for example on “Known Enemy” is in regards to the python language! I had assumed as I was playing javaScript it was part of the language as well. I’ve just been going through this on my own by myself.

Cheers!


#3

Yes, in javascript you use this, but in python it’s self.

Cheers