According to another stackoverflow question, "Are two functions equal?", it is impossible to verify if one function equals another.
This has me wondering how target.removeEventListener(type, listener)
is implemented.
Observe my sample code:
function eventHandler() {
alert("hello!");
document.removeEventListener("click", eventHandler);
}
document.addEventListener("click", eventHandler);
When I click anywhere in the document an alert box will pop up and show me "hello!". When I dismiss the alert box and click anywhere in the document again, nothing happens.
I can of course register multiple listeners on the same target for the same event. I can even register multiple listeners with the same name.
How does it work?