EventEmitter.prototype.addListener = function(type, listener) {
var m;
- if (typeof type !== 'string')
- throw TypeError('type must be a string');
if (typeof listener !== 'function')
throw TypeError('listener must be a function');
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
- if (typeof type !== 'string')
- throw TypeError('type must be a string');
if (typeof listener !== 'function')
throw TypeError('listener must be a function');
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
- if (typeof type !== 'string')
- throw TypeError('type must be a string');
if (typeof listener !== 'function')
throw TypeError('listener must be a function');
EventEmitter.prototype.removeAllListeners = function(type) {
var key, listeners;
- if (arguments.length > 0 && typeof type !== 'string')
- throw TypeError('type must not be set or must be a string');
-
if (!this._events)
return this;
};
EventEmitter.prototype.listeners = function(type) {
- if (typeof type !== 'string')
- throw TypeError('event type must be a string');
-
if (!this._events || !this._events[type])
return [];
if (typeof this._events[type] === 'function')
util.inherits(MyEE, EventEmitter);
function MyEE(cb) {
- this.emit('bar');
- this.on('foo', cb);
- process.nextTick(this.emit.bind(this, 'foo'));
+ this.once(1, cb);
+ this.emit(1);
+ this.removeAllListeners();
EventEmitter.call(this);
}
process.on('exit', function() {
assert(called);
+ assert.deepEqual(myee._events, {});
console.log('ok');
});