Glossary
Glossary Event listener

Event listener

Also known as: addEventListener, event handler, listener
TechWeb Standards

Definition

A function registered on a DOM node — or on window, document, a socket, an emitter — to run when a named event fires there: element.addEventListener('click', handler); the browser calls it with an event object, bubbling up from the target unless something stops it

The mechanism under every @click in a Vue template and every v-on; the framework adds and removes the listener for you, which is the main thing a framework does for events. Three things go wrong by hand: forgetting to remove one (a leak on every unmount), attaching hundreds where one on a parent would do (delegation — the bubbling is the point), and running expensive work on scroll or resize without throttling. The { passive: true } option tells the browser a scroll listener will not call preventDefault, which is what keeps scrolling smooth.

Tech

The browser is an event loop with a page attached. A listener is how a page says which events it cares about; everything else is the browser’s to handle at its own speed.

Related Terms

  • a: Appearance
  • ?: Keyboard shortcuts