You have several options:
You can bind the methods themselves:
this.method1 = this.method1.bind(this); this.method2 = this.method2.bind(this);
There bind the operator if you are using Babel (or some other transporter). It has not yet been accepted into the standard, so I would be tired of using it. Using the bind operator, you can make the equivalent:
this.method1 = ::this.method1 this.method2 = ::this.method2
Another option is to do what you have already done, just adjusted.
You must bind a method, not the result of forEach.
this.eventButtons.forEach(button => button.addEventListener('click', this.method1.bind(this)));
or with op binding:
this.eventButtons.forEach(button => button.addEventListener('click', ::this.method1));
Finally, you can also create a wrapper function using arrow notation for the lexical region:
this.eventButtons.forEach(button => button.addEventListener('click', (...params) => this.method1(...params)));
source share