Sunday, April 1, 2012

Node.js: EventEmitter and Observer pattern

The EventEmitter is the base building block for all compositions that would need to broadcast data to multiple consumers. Whenever there is an object that represents the source of several kinds of events, node.js usually makes the underlying class inherit from EventEmitter. The EventEmitter implementation makes use of the observer pattern by providing the ‘on’ function for objects that are interested in listening to an event. For e.g. you can listen to a specific event by calling the 'on()' function on your object, providing the name of the event, as well as a callback closure as the parameters. Read more..

No comments: