shorten some lines in events.js
This commit is contained in:
parent
ae8f8e7258
commit
6bdc42cee7
@ -1,8 +1,8 @@
|
|||||||
exports.EventEmitter = process.EventEmitter;
|
var EventEmitter = exports.EventEmitter = process.EventEmitter;
|
||||||
|
|
||||||
var isArray = Array.isArray;
|
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 there is no 'error' event listener then throw.
|
||||||
if (type === 'error') {
|
if (type === 'error') {
|
||||||
if (!this._events || !this._events.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
|
// EventEmitter is defined in src/node_events.cc
|
||||||
// process.EventEmitter.prototype.emit() is also defined there.
|
// EventEmitter.prototype.emit() is also defined there.
|
||||||
process.EventEmitter.prototype.addListener = function (type, listener) {
|
EventEmitter.prototype.addListener = function (type, listener) {
|
||||||
if ('function' !== typeof listener) {
|
if ('function' !== typeof listener) {
|
||||||
throw new Error('addListener only takes instances of Function');
|
throw new Error('addListener only takes instances of Function');
|
||||||
}
|
}
|
||||||
@ -76,9 +76,9 @@ process.EventEmitter.prototype.addListener = function (type, listener) {
|
|||||||
return this;
|
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) {
|
if ('function' !== typeof listener) {
|
||||||
throw new Error('removeListener only takes instances of Function');
|
throw new Error('removeListener only takes instances of Function');
|
||||||
}
|
}
|
||||||
@ -101,13 +101,13 @@ process.EventEmitter.prototype.removeListener = function (type, listener) {
|
|||||||
return this;
|
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]
|
// does not use listeners(), so no side effect of creating _events[type]
|
||||||
if (type && this._events && this._events[type]) this._events[type] = null;
|
if (type && this._events && this._events[type]) this._events[type] = null;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
process.EventEmitter.prototype.listeners = function (type) {
|
EventEmitter.prototype.listeners = function (type) {
|
||||||
if (!this._events) this._events = {};
|
if (!this._events) this._events = {};
|
||||||
if (!this._events[type]) this._events[type] = [];
|
if (!this._events[type]) this._events[type] = [];
|
||||||
if (!isArray(this._events[type])) {
|
if (!isArray(this._events[type])) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user