I'm trying to understand how events in JavaScript work, and I have a VERY simple question. Say the following code:
const client = require('someLibrary')
let eventSource;
client.on('event', => {
eventSource = client.someRandomThing
})
eventSource.on('event', => {
// Anything here doesn't work.
})
I understand why the code won't work. The eventSource.on() is defined before the client.on('event'), but how would I create the eventSource handler AFTER eventSource changes from null (inside the client.on() section)?
This isn't a duplicate question, because I understand how to view a variable after it's been changed, but how would I directly call a handler?