-
-
Save joshkehn/1383843 to your computer and use it in GitHub Desktop.
Hands-On Node Event Emitter Exercise 1
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 util = require('util'); | |
// Here is the Ticker constructor | |
var Ticker = function() { // This is a pseudo-class | |
} | |
util.inherits(Ticker, EventEmitter); | |
// Emit tick on the tick event | |
Ticker.prototype.tick = function() { | |
this.emit('tick event', 'tick'); | |
} | |
var ticker = new Ticker(); | |
ticker.on('tick event', function () { | |
console.log('Caught tick event.'); | |
}); | |
setInterval(function () { | |
ticker.tick(); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment