DELAPARRA
Index
Color
NL
Category: Programming paradigms

Event Listener / Handler

Explained by Updated

What is Event Listener / Handler?

Event Listener / Handler: A function registered to run when a specific event occurs. element.addEventListener('click', handleClick) registers handleClick to run on every click. An event listener, or handler, is a function registered to run when a specific event happens. In the browser, button.addEventListener('click', handleClick) runs handleClick on every click. In Laravel, a listener class runs when a matching event is dispatched.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Event Listener / Handler

How is Event Listener / Handler used in practice?

Listeners keep code decoupled. The part that triggers the event does not need to know who reacts to it, and you can add a new reaction without changing existing code.

What should you keep in mind with Event Listener / Handler?

Two things to watch. In front-end code, remove listeners when they are no longer needed, especially in single-page applications, or they pile up and cause memory leaks and duplicate actions. On the server, slow listeners, such as ones that call external APIs, should run on a queue. Otherwise one slow listener makes the whole request wait.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with E

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.