Skip to content

Instantly share code, notes, and snippets.

@mariyadiminsky
Last active August 10, 2016 09:04
Show Gist options
  • Save mariyadiminsky/e3d4cf4ffbec72ddf7fee5b38da9f9c2 to your computer and use it in GitHub Desktop.
Save mariyadiminsky/e3d4cf4ffbec72ddf7fee5b38da9f9c2 to your computer and use it in GitHub Desktop.
// 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