Reputation: 1365
The following code shows the contents of the events
object.
const events = require('events');
console.log(events);
The output is,
{ [Function: EventEmitter]
EventEmitter: [Circular],
usingDomains: false,
defaultMaxListeners: [Getter/Setter],
init: [Function],
listenerCount: [Function] }
There must be a benefit to using a circular reference for EventEmitter
and not the rest but I'm not sure what it is. Why did they construct the events
object using this pattern?
Upvotes: 1
Views: 202
Reputation: 723
There must be a benefit to using a circular reference for
EventEmitter
It was probably done for backwards compatibility.
Documentation for the events
module wayyyy back suggests it was the only way to import EventEmitter
.
"To access the EventEmitter class, require('events').EventEmitter
"
Upvotes: 2