Skip to content Skip to sidebar Skip to footer

Event Handlers & Event Listeners Independent Of One Another?

I have a question in regards to an aspect of event-driven programming. I am not sure whether the code for event handlers and event listeners should be completely independent from

Solution 1:

i think the listener is just some code to gather data and send data to logic code when the event triggers.

the logic code just care about the input data and do task, it is event independent

the code is like this:

functionsayHello(name) {  // this code is independentconsole.log("hello" + name);
}

element.addEventListener("click", function () {
  var name = "gather data dependent on the event and context"; // code here is event depentdentsayHello(name);
}, false);

so: logic is independent. how to get data is dependent

Post a Comment for "Event Handlers & Event Listeners Independent Of One Another?"