像这样的几个事件只有一个监听器:
// emitter is an instance of events.EventEmitter..
emitter.on('event1', listener);
emitter.on('event2', listener);
emitter.on('event3', listener);
emitter.on('event4', listener);
function listener() {
// I need to find which event was emitted and as a result, this listener was called.
}
请注意,这arguments.callee.caller.name
在 Node 中不起作用,因为events.EventEmitter.on
方法调用匿名函数,因此callee.caller
没有名称!
谢谢!