In JavaScript, for an event handler that needs access to private members and functions, I can rely on the function scope of those to be accessible within my event handler function, and do something like this:
theElement.addEventListener(click, onClick);
and later:
theElement.removeEventListener(click, onClick);
In TypeScript, I need to use an anonymous function to have this
be the containing object, like so:
theElement.addEventListener(click, (event) => this.onClick(event));
In this case, I can't remove the anonymous function from the listening to the event. How do I have an event listener as part of a class (with access to private fields and methods), that I can remove later?