+ 2
How to pass event and arguments to a event handler function?
Here is the code for it but i can't figure out how to pass event to it as well. Ty for the help! https://code.sololearn.com/W4JmPwxQKPF3/?ref=app
8 Antworten
+ 2
This solution works but it would be great if someone can explain what is actually happening here ,
d.onclick=test.bind(d,"arg");
function test(arg,e){
console.log(arg,this,e);
}
As i understand it is binding the object and the extra arguments to function, so we are able to access the object properties like event and the arguments as well!
+ 2
Runtime Terror that makes sense and i just didn't thought about passing e like that so tyvm !
+ 2
"event" object is accessible by any function that called by event listeners. we don't need passing it as an argument. but it always is the default value of first parameter .
means that if we don't pass any argument to function, first argument is equal to event object.
Note: event keyword is deprecated.
https://developer.mozilla.org/en-US/docs/Web/API/Window/event#browser_compatibility
https://code.sololearn.com/WI3HjAo66TL1/?ref=app
https://code.sololearn.com/WPLm4l1Ts7XR/?ref=app
+ 2
Mehran yes i figured that out , ty! By the way in second code of yours event is a window property and deprecated.
+ 2
Mehran check the comment by odlint on my code
+ 2
Abhay thanks.
+ 1
Abhay can you refer me to a page that says "event" is deprecated?