-
Book Overview & Buying
-
Table Of Contents
Node.js Design Patterns - Second Edition
By :
Another important and fundamental pattern used in Node.js is the observer pattern. Together with the reactor, callbacks, and modules, the observer pattern is one of the pillars of the platform and an absolute prerequisite for using many node-core and userland modules.
Observer is an ideal solution for modeling the reactive nature of Node.js and a perfect complement for callbacks. Let's give a formal definition as follows:
Pattern (observer) defines an object (called subject), which can notify a set of observers (or listeners), when a change in its state happens.
The main difference from the callback pattern is that the subject can actually notify multiple observers, while a traditional continuation-passing style callback will usually propagate its result to only one listener, the callback.
In traditional object-oriented programming, the observer pattern requires interfaces, concrete classes, and a hierarchy; in Node.js, all becomes much simpler...
Change the font size
Change margin width
Change background colour