Different implementations of the observer

The following implementations are available for the observer pattern:

  • Event dispatcher/listener
  • Publish/subscribe

Let's understand both the implementations in detail.

Event dispatcher/listener

The event dispatcher/listener (event emitter) implementation allows broadcasting data to more than one consumer. EventEmitter can be inherited in the case of more than one event represented by one object. We can use the on function for the EventEmitter implementation in the observer pattern to define objects for listening to an event. Objects in the event dispatcher implementation uses custom events that can be inherited from an event dispatcher object. It uses different kind of strings to identify the type of the event. ...

Get Test-Driven JavaScript Development now with O’Reilly online learning.

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