Skip to content
Browse files

updates to EventEmitter class (events -> _events, etc)

  • Loading branch information...
1 parent c490091 commit 06d07c9dee21cd9e3c87fe3004997c4d3f2c54d7 @majek majek committed May 22, 2012
Showing with 15 additions and 8 deletions.
  1. +15 −8 lib/eventemitter.js
View
23 lib/eventemitter.js
@@ -7,25 +7,32 @@
*/
var EventEmitter = function(events) {
- this.events = events || [];
+ var that = this;
+ that._events = events || [];
};
EventEmitter.prototype.emit = function(type) {
var that = this;
+ that._verifyType(type);
+ if (that._nuked) return;
+
var args = Array.prototype.slice.call(arguments, 1);
- if (!that.nuked && that['on'+type]) {
+ if (that['on'+type]) {
that['on'+type].apply(that, args);
}
- if (utils.arrIndexOf(that.events, type) === -1) {
+};
+EventEmitter.prototype._verifyType = function(type) {
+ var that = this;
+ if (utils.arrIndexOf(that._events, type) === -1) {
utils.log('Event ' + JSON.stringify(type) +
- ' not listed ' + JSON.stringify(that.events) +
+ ' not listed ' + JSON.stringify(that._events) +
' in ' + that);
}
};
-EventEmitter.prototype.nuke = function(type) {
+EventEmitter.prototype.nuke = function() {
var that = this;
- that.nuked = true;
- for(var i=0; i<that.events.length; i++) {
- delete that[that.events[i]];
+ that._nuked = true;
+ for(var i=0; i<that._events.length; i++) {
+ delete that[that._events[i]];
}
};

0 comments on commit 06d07c9

Please sign in to comment.
Something went wrong with that request. Please try again.