Browse Source

shorten some lines in events.js

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
6bdc42cee7
  1. 18
      lib/events.js

18
lib/events.js

@ -1,8 +1,8 @@
exports.EventEmitter = process.EventEmitter;
var EventEmitter = exports.EventEmitter = process.EventEmitter;
var isArray = Array.isArray;
process.EventEmitter.prototype.emit = function (type) {
EventEmitter.prototype.emit = function (type) {
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events || !this._events.error ||
@ -49,9 +49,9 @@ process.EventEmitter.prototype.emit = function (type) {
}
};
// process.EventEmitter is defined in src/node_events.cc
// process.EventEmitter.prototype.emit() is also defined there.
process.EventEmitter.prototype.addListener = function (type, listener) {
// EventEmitter is defined in src/node_events.cc
// EventEmitter.prototype.emit() is also defined there.
EventEmitter.prototype.addListener = function (type, listener) {
if ('function' !== typeof listener) {
throw new Error('addListener only takes instances of Function');
}
@ -76,9 +76,9 @@ process.EventEmitter.prototype.addListener = function (type, listener) {
return this;
};
process.EventEmitter.prototype.on = process.EventEmitter.prototype.addListener;
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
process.EventEmitter.prototype.removeListener = function (type, listener) {
EventEmitter.prototype.removeListener = function (type, listener) {
if ('function' !== typeof listener) {
throw new Error('removeListener only takes instances of Function');
}
@ -101,13 +101,13 @@ process.EventEmitter.prototype.removeListener = function (type, listener) {
return this;
};
process.EventEmitter.prototype.removeAllListeners = function (type) {
EventEmitter.prototype.removeAllListeners = function (type) {
// does not use listeners(), so no side effect of creating _events[type]
if (type && this._events && this._events[type]) this._events[type] = null;
return this;
};
process.EventEmitter.prototype.listeners = function (type) {
EventEmitter.prototype.listeners = function (type) {
if (!this._events) this._events = {};
if (!this._events[type]) this._events[type] = [];
if (!isArray(this._events[type])) {

Loading…
Cancel
Save