I am in need of an explanation of events and event emitters. I tried reading up on some tutorials but am confused. Please try to explain as If I was a 5 year old.
Take this code for example:
var EventEmitter = require("events").EventEmitter;
var ee = new EventEmitter();
ee.on("someEvent", function () {
console.log("event has occured");
});
if(1==1) {
ee.emit("someEvent");
}
What I am wondering about is why not just do this:
if(1==1) {
console.log("event has occured");
}
What is the purpose of naming an event and emitting it(aka calling it). Why would you use an event emitter? Provide useful code so I understand it's use.
P.S :
Could you emit a number event? ee.emit(12); and call it
ee.on(12, function () {console.log("yay?!")});