Thursday, October 6, 2011

JavaScript has this peculiar thing called "this". Beginners like me spend lot of time debugging code because somewhere in some distant corner of the code, a function is having an alien "this".

Inside the method of a class, "this" refers to the object on which the method has been called, thus (sounds like past participle of "this", doesn't it?) allowing us to access the members of the object. So far so good, but things start getting weird (at least for the first time) when we want to use methods of objects as callback functions for some events.