3 ms·
There's already a proposal for field declarations, where you can do the following: class Foo { bar = () => { console.log(this); } } This bas
by bramen 9y ago
There's already a proposal for field declarations, where you can do the following:
class Foo {
bar = () => {
console.log(this);
}
}
This basically puts `this.bar = () => console.log(this)` in the constructor, and since it's an arrow function it captures the correct context.
See https://github.com/tc39/proposal-class-fields https://github.com/tc39/proposal-class-fields.