[javascript] Eventsss

Viewer

copydownloadembedprintName: Eventsss
  1.  
  2. const EventEmitter = require("events")
  3.  
  4. const newEmitter = new EventEmitter()
  5.  
  6. newEmitter.on("anevent",()=>{
  7.     console.log("An event is ")
  8. })
  9. newEmitter.on("anotherevent",()=>
  10. {
  11.     console.log("Another event occurred")
  12. })
  13. newEmitter.off(("anotherevent"),()=>{
  14.     console.log("Another event stopped")
  15. })
  16. //Event handlers are executed in the order of their events emitted
  17. newEmitter.emit("anotherevent")  
  18. newEmitter.emit("anevent");

Editor

You can edit this paste and save as new:


File Description
  • Eventsss
  • Paste Code
  • 18 Apr-2024
  • 453 Bytes
You can Share it: