summaryrefslogtreecommitdiff
path: root/lib/events.js
diff options
context:
space:
mode:
authorRaynos <raynos2@gmail.com>2013-05-13 13:04:06 -0600
committerisaacs <i@izs.me>2013-08-19 17:27:08 -0700
commit6ed861dd7feea33224d1cac8e64010b45974ae51 (patch)
treeb1cd7bbb99a5357147a1940c1ff56ece10019a95 /lib/events.js
parentc171c490f2d850f63a37496bc7b31855193ce298 (diff)
downloadnodejs-6ed861dd7feea33224d1cac8e64010b45974ae51.tar.gz
nodejs-6ed861dd7feea33224d1cac8e64010b45974ae51.tar.bz2
nodejs-6ed861dd7feea33224d1cac8e64010b45974ae51.zip
events: have events module exports EventEmitter
This change is 100% backwards compatible. This change will make using `EventEmitter` slightly simpler / nicer and adheres to the best practice set forth by substack. ```js var EventEmitter = require("events") var emitter = new EventEmitter() ``` The only difference is that we now have to set `EventEmitter` as a property of `EventEmitter` for backwards compatibility like we do with [`Stream`][1] We have also set the `usingDomains` property on the `EventEmitter` constructor itself because that aligns with it's current usage of `require("events").usingDomains = true` There are other internals that would benefit from this change as well like `StringDecoder`
Diffstat (limited to 'lib/events.js')
-rw-r--r--lib/events.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/events.js b/lib/events.js
index 729800864..e2e39fd6e 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -22,11 +22,9 @@
var domain;
var util = require('util');
-exports.usingDomains = false;
-
function EventEmitter() {
this.domain = null;
- if (exports.usingDomains) {
+ if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
domain = domain || require('domain');
if (domain.active && !(this instanceof domain.Domain)) {
@@ -36,7 +34,12 @@ function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
}
-exports.EventEmitter = EventEmitter;
+module.exports = EventEmitter;
+
+// Backwards-compat with node 0.10.x
+EventEmitter.EventEmitter = EventEmitter;
+
+EventEmitter.usingDomains = false;
EventEmitter.prototype.domain = undefined;
EventEmitter.prototype._events = undefined;