2 ms·
Agree on class fields but there's high demand. I haven't examined the exact detail but it seems hard to please both sides here. Not sure what the best way forwa
by lucideer 9y ago
Agree on class fields but there's high demand. I haven't examined the exact detail but it seems hard to please both sides here. Not sure what the best way forward is.
On .bind(this), that's exactly what I meant by keeping the old system. "Fixing" that magically would have required underlying changes. That said, since you brought up class fields and bind in the same post, there's always:
class Dog {
bark() { console.log('Bark!'); }
eat = (food) => console.log('Munch');
}
feedDog(dog.eat);
- dmitriid 9y agoTrue, and that's what people use extensively. Class fields break `extends` though :)
- 52-6F-62 9y agoMy favourite solution so far is the @autobind decorator. It's far from native yet, though. And of course, enters the newer decorators feature which drifts ever closer to Java-like syntax to some peoples' chagrin. https://github.com/andreypopp/autobind-decorator https://github.com/andreypopp/autobind-decorator