Skip to content
Advertisement

use “this” in a function passed to eventListener

Hello people I was refactoring some code and couldn’t figure a way to reuse the ‘this’:

a/ Code I have

JavaScript

b/ I want to move the function to another file and export it as:

JavaScript

and use it like:

JavaScript

but ‘this’ is undefined.. how do I bind it?

Advertisement

Answer

Pass this as parameter to function (and also decouple from event too):

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement