开发者

node.js eventemitter create multiple objects or rely on arguments?

Asking about eventemitters in node.js

For different events, should I create new emitters on a base object:

forum.closeThread = new ee()
forum.openThread = new ee()
forum.openThread.on(threadID, foo) 

or rely on arguments to trigger

forum.events.on('openThread', foo)
forum.eve开发者_开发知识库nts.on('closeThread', bar)
var bar = function (threadID) {...}

What is recommended?

Thanks.


I find the latter more readable

forum.on('thread-open', threadID, foo)
forum.on('thread-close', threadID, bar)

I would make forum extend EventEmitter myself.

var Forum = function() {
    ...
}

Forum.prototype = new events.EventEmitter;

var forum = new Forum();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜