【发布时间】:2012-02-12 11:30:43
【问题描述】:
我在很多 Node.js 库中都看到了这种模式:
Master.prototype.__proto__ = EventEmitter.prototype;
(来源here)
有人可以举个例子向我解释一下,为什么这是一种常见的模式,什么时候很方便?
【问题讨论】:
-
请参阅此问题以获取信息stackoverflow.com/questions/5398487/…
-
注意
__proto__是反模式,请使用Master.prototype = Object.create(EventEmitter.prototype); -
其实用
util.inherits(Master, EventEmitter); -
@Raynos 什么是反模式?
-
现在使用 ES6 类构造函数更容易。在此处检查兼容性:kangax.github.io/compat-table/es6。检查下面的文档或我的答案。
标签: node.js eventemitter