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 15The Observer Pattern

In an event-driven environment, such as the browser where it is constantly seeking attention from a user, the observer pattern, also known as the publisher-subscriber pattern, is an excellent tool to manage the relationship between people and their jobs, or rather, objects, their actions, and their state. In JavaScript terms, this pattern essentially allows you to observe the state of an object in a program and be notified when it changes.

In the observer pattern, there are two roles: the observer and the observed (watch or be watched). In this book, we generally like to refer to them as publishers and subscribers. This model can be implemented several ways in JavaScript, and we take a look at a few of them in ...

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