What’s the difference between an event handler and an event listener?
Up until recently I considered them to be different names for the same thing: a function that’s called when an event occurs. But I read something recently that referred to the event handler as the DOM element to which the event listener was bound, which would make sense.
Just to be perfectly clear, the language itself does not have the concept of events. These are part of the DOM.
Event Handler: An asynchronous callback that is invoked when an event is raised. Event Listener: An object that implements an interface and has events "pushed" to it.In the context of DOM events the interface used is this:
Then you register a listener like this:
Here is the documentation from MDC:
So it looks like function objects implicitly implement EventListener for ease of use.
Analogies
Think of Event Handler as giving the mailman instructions.
Think of Event Listener as waiting to see your doctor.
At the end of the day though these are simply abstractions for
Resources
Event Handler
Observer Pattern