问题
What is the correct and professional way to add parameters to a function being passed to addEventListener()
or or being directly assigned to an event handlers as in el.onclick = doSomething(param);
回答1:
You can use an anonymous function when you need to pass parameters to another, like this:
el.addEventListener("click", function() { doSomething(param); }, false);
Whereas if it didn't need parameters, it would just be:
el.addEventListener("click", doSomething, false);
来源:https://stackoverflow.com/questions/4305196/how-to-pass-parameters-to-a-function-being-passed-as-an-argument-of-addeventlist