I like ES6 classes but I can't understand why I do have to bind methods in constructors like this:
constructor() {
this.someMethod = this.someMethod.bind(this)
}
I need to do this almost for any method.
Is this a real limitation or am I missing something? What is the reason behind this? I know that classes in JS are only syntactic sugar but this could have been part of them.
Quoting Mark Miller's answer to the linked esdiscuss post here:
And Kevin Smith's answer:
That said, the public class fields proposal will allow you to define instance methods as
(instead of doing the same in the
constructor
).