What is DOM Event delegation?

  1. Home
  2. javascript
  3. What is DOM Event delegation?

Can anyone please explain event delegation in JavaScript and how is it useful?

First answer

Second answer

dom event delegation is something different from the computer science definition.

It refers to handling bubbling events from many elements, like table cells, from a parent object, like the table. It can keep the code simpler, especially when adding or removing elements, and saves some memory.

Third answer

Delegation is a technique where an object expresses certain behavior to the outside but in reality delegates responsibility for implementing that behaviour to an associated object. This sounds at first very similar to the proxy pattern, but it serves a much different purpose. Delegation is an abstraction mechanism which centralizes object (method) behavior.

Generally spoken: use delegation as alternative to inheritance. Inheritance is a good strategy, when a close relationship exist in between parent and child object, however, inheritance couples objects very closely. Often, delegation is the more flexible way to express a relationship between classes.

This pattern is also known as “proxy chains”. Several other design patterns use delegation – the State, Strategy and Visitor Patterns depend on it.

Spread the love

Related articles

Comments are closed.