Skip to content

Commit 06d07c9

Browse files
committed
updates to EventEmitter class (events -> _events, etc)
1 parent c490091 commit 06d07c9

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/eventemitter.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,32 @@
77
*/
88

99
var EventEmitter = function(events) {
10-
this.events = events || [];
10+
var that = this;
11+
that._events = events || [];
1112
};
1213
EventEmitter.prototype.emit = function(type) {
1314
var that = this;
15+
that._verifyType(type);
16+
if (that._nuked) return;
17+
1418
var args = Array.prototype.slice.call(arguments, 1);
15-
if (!that.nuked && that['on'+type]) {
19+
if (that['on'+type]) {
1620
that['on'+type].apply(that, args);
1721
}
18-
if (utils.arrIndexOf(that.events, type) === -1) {
22+
};
23+
EventEmitter.prototype._verifyType = function(type) {
24+
var that = this;
25+
if (utils.arrIndexOf(that._events, type) === -1) {
1926
utils.log('Event ' + JSON.stringify(type) +
20-
' not listed ' + JSON.stringify(that.events) +
27+
' not listed ' + JSON.stringify(that._events) +
2128
' in ' + that);
2229
}
2330
};
2431

25-
EventEmitter.prototype.nuke = function(type) {
32+
EventEmitter.prototype.nuke = function() {
2633
var that = this;
27-
that.nuked = true;
28-
for(var i=0; i<that.events.length; i++) {
29-
delete that[that.events[i]];
34+
that._nuked = true;
35+
for(var i=0; i<that._events.length; i++) {
36+
delete that[that._events[i]];
3037
}
3138
};

0 commit comments

Comments
 (0)