Class Eventemitter {constructor () {This.emitter = {}}on (EVENTNAME,CB) {if (This.emitter[eventname]) {this.emitter[ Eventname].push (CB)} else {This.emitter[eventname] = []this.emitter[eventname].push (CB)}}emit (eventName,... str) {if (This.emitter[eventname]) {for (Let item of This.emitter[eventname]) {item (... str)}} else {throw EventName + ' is not Definde ';}}} Const Eventemitter = new Eventemitter (), const Connecthandler = (STR,STR1) and {console.log (' connection succeeded 1. ' +str,str1 '); Eventemitter.emit (' data_received ');} Eventemitter.on (' connection ', Connecthandler); Eventemitter.on (' Connection ', (str,str1) = {Console.log (' connection succeeded 2. ' +str,str1;}); Eventemitter.on (' data_received ', () =>{console.log (' Data received successfully. ')}); Eventemitter.emit (' Connection ', ' teststr ', ' xxxxxx '); Console.log (' program execution completed. ‘)
NodeJs---Emitter module (analog package)