javascript - Can't get token.remove() working in Facebook Emitter -
any idea why facebook emitter not working token.remove()
call below:
console:
$ node main.js 5 10 /users/carlf/documents/dev/test/emitter/emit-node.js:21 token.remove(); ^ typeerror: undefined not function
my code:
var {eventemitter} = require('./node_modules/emitter'); var emitter = new eventemitter(); var token = emitter.addlistener('event', function(x, y) { console.log(x, y); }); emitter.emit('event', 5, 10); // listener prints "5 10". token.remove(); emitter.emit('event', 9, 11); // nothing logged
that error telling remove not function. remove listener need call removelistener
method of instance of eventemitter
passing name of event , callback provided. try this:
var {eventemitter} = require('./node_modules/emitter'); var emitter = new eventemitter(); function handler(x, y) { console.log(x,y); } emitter.addlistener('event', handler); emitter.emit('event', 5, 10); // listener prints "5 10". emitter.removelistener('event', handler); emitter.emit('event', 9, 11); // nothing logged
Comments
Post a Comment