joyent/node — pull request #3397 by pgte (2012-06-09 21:27:07+00:00)
Title: EventEmitter.onAny

This patch allows to listen to all events emitted by an event emitter using:

```javascript
emitter.onAny(function(eventType, args) {
console.log('emitter emitted event type "%s" with args %j', eventType, args);
});
```

or, alternatively:

```javascript
emitter.on('*', function(eventType, args) {
console.log('emitter emitted event type "%s" with args %j', eventType, args);
});
```

I have benchmarked EventEmitter, and came to the conclusion that it is impossible to introduce a change like this in `EventEmitter.prototype.emit` without any serious performance regression.

This solution, however, does not introduce any performance penalty if the user is not listening to all events. This is done by wrapping `emitter.emit` on demand.

Also, I am unwrapping if the user removes all the event listeners for event type "*".