Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 06d07c9dee21cd9e3c87fe3004997c4d3f2c54d7 1 parent c490091
Marek majek authored

Showing 1 changed file with 15 additions and 8 deletions. Show diff stats Hide diff stats

  1. +15 8 lib/eventemitter.js
23 lib/eventemitter.js
@@ -7,25 +7,32 @@
7 7 */
8 8
9 9 var EventEmitter = function(events) {
10   - this.events = events || [];
  10 + var that = this;
  11 + that._events = events || [];
11 12 };
12 13 EventEmitter.prototype.emit = function(type) {
13 14 var that = this;
  15 + that._verifyType(type);
  16 + if (that._nuked) return;
  17 +
14 18 var args = Array.prototype.slice.call(arguments, 1);
15   - if (!that.nuked && that['on'+type]) {
  19 + if (that['on'+type]) {
16 20 that['on'+type].apply(that, args);
17 21 }
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) {
19 26 utils.log('Event ' + JSON.stringify(type) +
20   - ' not listed ' + JSON.stringify(that.events) +
  27 + ' not listed ' + JSON.stringify(that._events) +
21 28 ' in ' + that);
22 29 }
23 30 };
24 31
25   -EventEmitter.prototype.nuke = function(type) {
  32 +EventEmitter.prototype.nuke = function() {
26 33 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]];
30 37 }
31 38 };

0 comments on commit 06d07c9

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