Last active
August 10, 2016 09:04
-
-
Save mariyadiminsky/e3d4cf4ffbec72ddf7fee5b38da9f9c2 to your computer and use it in GitHub Desktop.
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
// First require in the EventEmitter Object | |
var EventEmitter = require('events').EventEmitter; | |
// Create a new instance of the EventEmitter | |
var bunnyError = new EventEmitter(); | |
// This is where you create your bunnyError event | |
// and create a callback that will be triggered when | |
// bunnyError is called | |
bunnyError.on('bunnyWarning', function(warning) { | |
console.log(`BUNNY WARNING: ${warning}`); | |
}); | |
// Triggers bunnyError event. | |
bunnyError.emit('bunnyWarning', 'Not enough blueberries!!'); | |
bunnyError.emit('bunnyWarning', 'You brought a dog!'); | |
bunnyError.emit('bunnyWarning', 'Pooped on the carpet again.'); | |
// Lets create another event! | |
bunnyError.on('bunnyNeed', function(need) { | |
console.log(`I need ${need}`); | |
}) | |
// Now lets trigger the bunnyNeed event! | |
bunnyError.emit('bunnyNeed', 'a potato.'); | |
bunnyError.emit('bunnyNeed', 'a tomato.'); | |
bunnyError.emit('bunnyNeed', 'hugs.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment