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

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

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