Skip to content

Instantly share code, notes, and snippets.

@rvagg
Created February 24, 2014 21:39
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 rvagg/9197724 to your computer and use it in GitHub Desktop.
Save rvagg/9197724 to your computer and use it in GitHub Desktop.
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter;
var tick = true;
var count = 0;
setInterval(function() {
count ++;
if (tick) emitter.emit('tic', count);
else emitter.emit('tac', count);
tick = !tick;
}, 1000);
emitter.on('tic', function(count) {
console.log('[%d] TIC', count);
});
emitter.on('tac', function(count) {
console.log('[%d] TAC', count);
});
function listener (event, count) {
console.log('listener', event, 'got', count, 'this =', this)
}
emitter.on('tic', function (count) {
//listener('tic', count)
})
var a
emitter.on('tic', a = listener.bind({ s: 'my new "THIS!"' }, 'tic'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment