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();
精彩评论