Created
January 1, 2014 21:56
-
-
Save lookingcloudy/8211904 to your computer and use it in GitHub Desktop.
NodeJS Inheriting from EventEmmitter class
This file contains hidden or 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 sys = require('sys'), | |
events = require('events'); | |
function Downloader() { | |
if(false === (this instanceof Downloader)) { | |
return new Downloader(); | |
} | |
events.EventEmitter.call(this); | |
} | |
sys.inherits(Downloader, events.EventEmitter); | |
Downloader.prototype.download = function(episode) { | |
var self = this; | |
var statusMessage = 'Downloading: ' + episode; | |
self.emit('status', statusMessage); | |
setTimeout(function() { | |
var finishedMessage = 'Downloaded ' + episode; | |
self.emit('finished', finishedMessage); | |
}, 5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment