//Event Emitter, listening to requests const EventEmitter = require("events"); class Sales extends EventEmitter { constructor() { super(); } } const myEmitter = new Sales(); myEmitter.on("newSale", () => { console.log("There was a new sale"); }); myEmitter.on("newSale", (stock) => { console.log(`There are now ${stock} items left in stock.`); }); myEmitter.emit("newSale", 9);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter