Re:JavaScript: prototype vs. class
by lucideer on Wednesday April 04, 2018 @11:43AM
(#16755786)
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);
Re:JavaScript: prototype vs. class
by 52-6F-62 on Wednesday April 04, 2018 @12:25PM
(#16756254)
My 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.
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: