There is a bit more nuance in using `this` in a named function that wasn't covered. Named functions defined in classes are scoped outside of the class, meaning they are not bound to the class. To use `this` in your named function, you usually have to bind it in the constructor using `this.functionName.bind(this)`Arrow functions defined within a class are scoped and bound to the class automatically. Hence, arrow functions do not require calling the .bind in constructor, and you can happily use `this` inside arrow functions.
moritzwarhier|8 months ago
If you define
then will return "Hello"while
will throw an error.This predates generator functions and classes (which are only syntax sugar AFAIK).
And it seems like a glaring omission giving the submission title.
I'm ashamed though if it's in there and I missed it.
The behavior is called "late binding".
WorldMaker|8 months ago
postalrat|8 months ago