DEV Community

So Sun Park
So Sun Park

Posted on

addeventlistener with class method and bind

I wanted to write addeventlistener inside a class constructor. But then, javascript requires classMethod.bind(this) and that sometimes is annoying to be used with addeventListener because that also send 'event' to callback classMethod.

The biggest winner is

making classMethod as () => { } arrow function.
Then it wouldn't mess up your this. inside class method.
Enter fullscreen mode Exit fullscreen mode

https://stackoverflow.com/questions/21298918/is-it-possible-to-call-a-class-method-with-addeventlistener

Top comments (0)