diff --git a/lib/eventemitter2.js b/lib/eventemitter2.js index 02bd923e..1b8522a9 100644 --- a/lib/eventemitter2.js +++ b/lib/eventemitter2.js @@ -89,7 +89,7 @@ var growListenerTree = function(type, listener) { ~type.indexOf(this.delimiter)) { this.emit('error', 'bad event name: ' + type); } - + type = type.split(d); var tree = this.listenerTree; @@ -98,7 +98,7 @@ var growListenerTree = function(type, listener) { while (name) { if (!tree[name]) { - tree[name] = {}; + tree[name] = new Object(); } tree = tree[name]; @@ -164,6 +164,7 @@ EventEmitter2.prototype.many = function(event, ttl, fn) { }; EventEmitter2.prototype.emit = function() { + this._events || this.init(); var type = arguments[0]; // If there is no 'error' event listener then throw. @@ -287,7 +288,6 @@ EventEmitter2.prototype.un = function(type, listener) { if(this.wildcard) { var ns = type.split(this.delimiter); - console.log(ns) var leaf = searchListenerTree.call(this, null, ns, this.listenerTree, 0); if('undefined' === typeof leaf) { return this; } diff --git a/test/perf/benchmark.js b/test/perf/benchmark.js index 0b392843..5383654f 100644 --- a/test/perf/benchmark.js +++ b/test/perf/benchmark.js @@ -11,7 +11,6 @@ var emitter2 = new EventEmitter2; var EventEmitter3 = require('events').EventEmitter; var emitter3 = new EventEmitter3; -// add tests suite .add('EventEmitterHeatUp', function() { @@ -23,7 +22,6 @@ suite }) .add('EventEmitter', function() { - emitter.on('test1', function () { 1==1; }); emitter.emit('test1'); emitter.removeAllListeners('test1'); @@ -37,14 +35,19 @@ suite }) - // add listeners + .add('EventEmitter2 (wild)', function() { + + emitter2.on('test2.foo', function () { 1==1; }); + emitter2.emit('test2.foo'); + emitter2.removeAllListeners('test2.foo'); + + }) + .on('cycle', function(event, bench) { console.log(String(bench)); }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').pluck('name')); }) - - // run async - .run(true); + .run(true);