在一个 主题 有关 EventEmitter
有人说,在下面的例子中,有没有必要使用活动。 它是毫无意义的:
const events = require("events")
const eventEmitter = new events.EventEmitter()
eventEmitter.on("say_hi", () => {console.log("sa")})
eventEmitter.emit("say_hi")
他说:
When you build a library or internal API, it allows other parts of your code (or people using your code) to subscribe to events without you needing to know this in advance.
For the case you used it above, it does not make sense.
但我不理解的含义,他的判决。
我不知道在所有时候使用 EventEmitter
和当使用 Function
.
在另一个 主题,他实现他的例子有两个 EventEmitter
和 Function
. 没有任何差别 execution
除了这一事件被分配到一个对象(称为student_max)如果它是要实现对于另一名学生,该事件必须改写的(即重复),但在功能的所有对象(所有学生)可以使用评分方法。
有人可以清楚地解释的例和代码时使用 EventEmitter
和当使用 Function
?