I have some sample code which binds an event handler as follows:
var h1=document.querySelector('h1');
h1.onclick=doit;
function doit(x) {
console.log(x);
}
When the event handler is triggered (by clicking on the h1 element), the output is an event object, as expected.
If I bind the event handler as follows:
h1.onclick=doit.bind(h1);
I get the same result.
However, if I bind it as follows:
h1.onclick=doit.bind(h1,1);
I get 1, the first parameter after h1. In all cases, the vallue of this is correctly set to h1, but in the last case, the passed parameter appears to replace the expected event object.
How can I keep the event object without rewriting the event handler as a function expression?