What is the difference between addListener(event, listener) and on(event, listener) method in node.js? -
here cannot understand basic difference between these 2 methods.
var events = require('events'); var eventemitter = new events.eventemitter(); var listner1 = function listner1() { console.log('listner1 executed.'); } var listner2 = function listner2() { console.log('listner2 executed.'); } eventemitter.addlistener('connection', listner1); eventemitter.on('connection', listner2); eventemitter.emit('connection');
.on()
same .addlistener()
in eventemitter object.
straight eventemitter source code:
eventemitter.prototype.on = eventemitter.prototype.addlistener;
sleuthing through github repository, there this checkin jul 3, 2010 contains comment: "experimental: 'on' alias 'addlistener'".
update in 2017: documentation eventemitter.prototype.addlistener()
says this:
alias
emitter.on(eventname, listener)
.
Comments
Post a Comment