This code
Door.prototype.__proto__ = events.EventEmitter.prototype
makes Door.prototype
inherit from events.EventEmitter.prototype
.
So the prototype chain will be like
doorInstance -> Door.prototype -> events.EventEmitter.prototype
This approach is similar to
Door.prototype = Object.create(events.EventEmitter.prototype)
The difference is that modifying the [[Prototype]] does not create a new object, but it has a great negative impact on performance.
Instead, this code
Door.prototype = events.EventEmitter.prototype
makes Door
instances inherit directly from events.EventEmitter.prototype
.
That is, you won't be able to add specific methods in Door.prototype
without polluting events.EventEmitter.prototype
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…