O'Reilly logo

Pro JavaScript™ Design Patterns by Dustin Diaz, Ross Harmes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required