Time for action – Using DOM level 2 events

In level 2, there is a function named removeEventListener (detachEvent is the equivalent of it in Internet Explorer's model).

This function allows one to remove an event listener. It only needs the type of the event (as a string) and the listener to be removed.

Unfortunately, every time you pass a reference to a function, the haXe compiler creates a closure. Closures are like functions enclosing functions and as such, the reference you pass to addEventListener and the one you pass to removeEventListener will never be equal, resulting in the removeEventListener function not being able to remove the listener.

This can be tested in a very simple way.

Create an HTML file with the markup for two buttons and ...

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.