0

How do you guys implement a substitue variable for this inside a class in TypeScript?

This technique is useful to save and recall your (parent/child) class or function when entering another code segment whereas this is replaced by the current context.

As in JS:

class Foo {
  var $this = this;
}

Meanwhile in TS, the keyword var is not allowed inside a class.

  • It would be `private $this = this;` but I have never had to do that in my Typescript code. For callbacks, use arrow functions. See [this post](https://stackoverflow.com/q/20279484/1009922) for more details. – ConnorsFan Aug 25 '18 at 02:45
  • Thanks Connor, I got the answer with arrow functions, though private $this = this could not be accessed – Long Nguyễn Aug 25 '18 at 03:02

0 Answers0