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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.