Skip to content

Instantly share code, notes, and snippets.

@joaquimserafim
Created October 23, 2014 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaquimserafim/73423e1cfabaefcafa09 to your computer and use it in GitHub Desktop.
Save joaquimserafim/73423e1cfabaefcafa09 to your computer and use it in GitHub Desktop.
tracing event emitter
var inherits = require('util').inherits;
var EventEmitter = require('events').EventEmitter;
var debug = require('debug')('emitter');
var sliced = require('sliced');
function Dummy() {
EventEmitter.call(this);
}
inherits(Dummy, EventEmitter);
Dummy.prototype._emit = function() {
var args = sliced(arguments);
debug('emit: ' + args);
this.emit.apply(this, args);
};
Dummy.prototype.read = function() {
this._emit('read');
};
Dummy.prototype.write = function(data) {
this._emit('write', data);
};
//
//
//
var test = new Dummy();
test.on('read', function() {
console.log('read');
});
test.on('write', function(data) {
console.log('write', data);
});
test.read();
test.read();
test.write('hello');
test.write('ahahah');
test.read();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment