4

我目前在一个应用程序中使用Publisher.js以及Microee,它是一个微小的 EventEmitter。在我看来,如果我有一个全局 microee 实例,它的使用方式与 pub/sub 大致相同。例如在 Publisher.js 我可以这样做:

publisher.subscribe('onAwesome', function (one, two, foo){
  console.log(one, two, foo);
});

publisher.publish('onAwesome', 1, 2, 'foo');

在 Microee 我可以做到:

microee.on('onAwesome', function (one, two, foo){
  console.log(one, two, foo);
});

microee.emit('onAwesome', 1, 2, 'foo');

所以我想知道在用事件发射器替换这个特定的发布/订阅用例时我是否遗漏了一些东西。

4

1 回答 1

4

不,您实际上是正确的 - 该代码可以直接替换EventEmitter

带有 EventEmitter 的事件在其事件调用中支持参数,以及您将从中受益的许多其他功能 - 假设您使用的是 Node.js。

于 2014-10-18T22:16:03.293 回答