# It allows programmer to add event listener and to emit the events. Where,
Event listener : It waits for event to occur such as “start”.
emitter : It broadcast the event for particular listener.
# EventEmitter provides multiple properties like on and emit. on property is used to bind a function with the event and emit is used to fire an event.
/**
* Created by Anand Dwivedi on 8/26/2016.
*/
var events =require('events');
var emitter=new events.EventEmitter();
emitter.on('customEvent',function (){
console.log('custom Event Loaded');
});
emitter.on('customEventParameter',function (name,place){
console.log(name+' is Staying in '+place);
});
emitter.emit('customEvent');
emitter.emit('customEventParameter','Anand','Bangalore');
Event listener : It waits for event to occur such as “start”.
emitter : It broadcast the event for particular listener.
# EventEmitter provides multiple properties like on and emit. on property is used to bind a function with the event and emit is used to fire an event.
/**
* Created by Anand Dwivedi on 8/26/2016.
*/
var events =require('events');
var emitter=new events.EventEmitter();
emitter.on('customEvent',function (){
console.log('custom Event Loaded');
});
emitter.on('customEventParameter',function (name,place){
console.log(name+' is Staying in '+place);
});
emitter.emit('customEvent');
emitter.emit('customEventParameter','Anand','Bangalore');
No comments:
Post a Comment