Node.js EventEmitter example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EventEmitter = require("events").EventEmitter; | |
var door = new EventEmitter(); | |
door.on("doorbell", function(seconds){ | |
console.log("Doorbell rang for " + seconds + " seconds."); | |
person.openDoor(); | |
}); | |
/* In another file, for example... */ | |
function ring(seconds) { | |
door.emit("doorbell", seconds); | |
} | |
ring(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment