Maintaining this as reference to Class

Topics: General
Mar 24, 2014 at 5:07 AM
Edited Mar 24, 2014 at 5:08 AM
I ran into this early on. The way that I've always had to do it is to expand out the this.g reference to a full lambda, i.e.:

this.d("name", () => this.g());

That's definitely a more awkward syntax, and I wish the TS team would figure out a way to make this stickier (it's definitely a violation of the Rule of Least Astonishment that sometimes this points to the current class, but not always), but it works.