- 1
How to add arguments to function without parentheses invoking in event listener?
function f(a, b){ alert(a + b) } document.getElementById("id").addEventListener('click', f); Here, I want to add arguments to click event function.
1 Resposta
0
that's not possible, or only by binding them (so you will loose the original 'this' value (element on wich the event is dispatched)... and the event object argument will be moved from as many arguments are provided (in addition to the 'this' value ^^
document.getElementById("id").addEventListener('click', f.bind(thisArg,arg1,arg2));
so function signature will catch arg1 as a and arg2 as b... third argument will be the event object and 'this' will hold the thisArg object ;)