Once removeEventListener is invoked, is it safe to assume that the removed handler will not be called? This is a somewhat broad question, so here are some specific examples.
- A button is clicked, and its click event is dispatched onto the execution queue. Before the event can be handled, removeEventListener is called, removing the button's event handler. What happens?
- A function is invoked which takes 3 milliseconds to complete. At the end of this function, removeEventListener is invoked, removing the click handler of a button. During this three-millisecond period, the button is clicked. Will the handler be invoked after the previous function is done executing?
Is it safe to perform cleanup actions in the same function that invokes removeEventListener, or must one use setTimeout or some other method of first ensuring that the execution queue is empty? Does this behavior vary among browsers?
Relevant documentation is also appreciated. Thanks in advance!