Created
June 26, 2014 11:28
-
-
Save oranheim/65e6fa778490902d244d to your computer and use it in GitHub Desktop.
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
'use strict'; | |
/** | |
* Created by ora on 27.03.14. | |
*/ | |
var EventEmitter = require('events').EventEmitter, | |
util = require('util'); | |
var EventService = function () { | |
this.events = {}; | |
}; | |
EventService.prototype.on = function(eventname, callback) { | |
this.events[eventname] || (this.events[eventname] = []); | |
this.events[eventname].push(callback); | |
}; | |
EventService.prototype.emit = function(eventname) { | |
var args = Array.prototype.slice(arguments, 1); | |
if (this.events[eventname]) { | |
this.events[eventname].forEach(function(callback) { | |
callback.apply(this, args); | |
}) | |
}; | |
}; | |
util.inherits(EventService, EventEmitter); | |
exports.EventService = EventService; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment