I want to reause one long function in multiple event listeners.
Is there a way I can reuse javascript functions in multiple event listeners (without jQuery or other libraries).
I've tried a few things.
function one(){
console.log("not supposed to show until I press the variable containing num1")
};
num1.addEventListener('click', one());
Runs the function at the beginning and doesn't run on click
num1.addEventListener('click', function one(){
console.log("oops")
});
num2.addEventListener('click', one());
Runs when I press num1 doesn't work when I pess num2
const one = () => {console.log("Still not working")}
num1.addEventListener('click', one());
same issue as with the first example.
I want to reause one long function in multiple event listeners.