emitter.addListener(eventName,
listener)
This
function add listener to this event.
Below
table summarizes the arguments of addListener function.
Argument
|
Type
|
Description
|
eventName
|
String
|
Event
name
|
Listener
|
Function
|
Callback
function to be called on this event emit
|
var EventEmitter = require('events').EventEmitter; var emitter = new EventEmitter(); emitter.addListener("welcome", (name) => { console.log("Hello Mr.%s", name); }); emitter.addListener("welcome", (name) => { console.log("Good Morning Mr.%s", name); }); emitter.emit("welcome", "krishna");
Output
Hello
Mr.krishna
Good Morning Mr.krishna
Good Morning Mr.krishna
No comments:
Post a Comment