I understand events such as onclick or onmosemove, but I find the concept of custom eventemitters a bit puzzling. I understand how it works. What I don't understand is why would someone use it instead of a simple function.
For example: consider the following code.
var events = require('events');
var myEmmitter = new events.EventEmitter();
myEmmitter.on('anEvent',function(msg){
console.log(msg);
});
myEmmitter.emit('anEvent','The event is absolutely emmited');
Would it not be simpler to create a function and call it where we are emitting the event instead? such as in the following.
myEmitter = function(msg){
cosole.log(msg);
}
myEmitter('the function is being called where it would have been emitted');