Using the this keyword with Typescript and a jQuery function
November 23, 2013
When you write Typescript, you’re forced by the compiler to use the “this” keyword when you want to access member variables or methods. If they’re static, you’re forced to use the name of the class (as you usually would in C#, although it’s syntactical).
The solution in Typescript is to use their lambda expression syntax to maintain scope, and with it the Typescript compiler uses a _this variable if needed and does it all for you. For example:
This compiles down to: