CHAPTER 17The Chain of Responsibility Pattern

In this chapter, we look at the chain of responsibility, which allows you to decouple the sender and the receiver of a request. This is accomplished by implementing a chain of objects that implicitly handles the request. Each object in the chain can handle the request or pass it on to the next object. This pattern is used internally in JavaScript to handle event capturing and bubbling. We explore how to use this pattern to create more loosely coupled modules and to optimize event attachment.

The Structure of the Chain of Responsibility

A chain of responsibility consists of several different types of objects. The sender is the object that makes the request. The receivers are the objects in the chain ...

Get Pro JavaScript™ Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.