Find which event called the listener in Node.js

There is only one listener attached to several events like this:

// 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.    
}

Please note that arguments.callee.caller.name won't work in Node, since events.EventEmitter.on method calls an anonymous function and therefore the callee.caller has no name!

Thanks!

I would just make an intermediary "function" for each listener if I really need to know who called it:

For example:

emitter.on('event1', function(){
    //something special with this event
    listener();
});

You could always pass the event as a string parameter to the listener function.

For example:

emitter.on('event1', function() {
    listener('event1');
});

Then your listener function could check for which event was called:

function listener(eventType) {
    if (eventType === 'event1')
        // Do something here
}