any of the above.
Events are a map of some sort of identifier and a callback.
For my websocket interface, which is C/C++ the events are tracked in C/C++ structures.
For a graph database I was tinkering with in ES6, the events are tracked in just javascript ojects.
A super simple way (and I'm sure there's lots of ways of doing this)
var myObjectWithEvents = { events : {},
on( event, callbackOrData ) {
if( typeof callbackOrData === "function" ) {
this.events[event] = callbackOrData; // register event handler
} else {
if( event in this.events ) {
this.events[event]( callbackOrData ); // invoke event handler
}
}
}
};
myObjectWithEvents.on( "click", (data)=>{ console.log( "got click event..." ) } ); /// register an event handler to 'click'
....
myObjectWithEvents.on( "click", { x:1, y : 250 } ); // trigger an event...
Instead of assigning directly, each event in 'events' could be an array ... [] and .push( callbackOrData ); would allow you to assign multiple handlers to each eent instead of a single... and then you'd just do something like this.events[event].forEach( cb=> cb( callbackOrData ) ) instead.
The above was something I got from Gun DB; if the argument passed to 'on' is a function, keep that function as a callback stored as the name of the event specified. If it's not a function, call any previously registered event with the data passed to 'on', which then overloads 'on' as both the uhh addEventListener() and the emit().