+ 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

28th Aug 2021, 8:31 PM
Abhay
Abhay - avatar
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!
28th Aug 2021, 10:24 PM
Abhay
Abhay - avatar
+ 2
Runtime Terror that makes sense and i just didn't thought about passing e like that so tyvm !
29th Aug 2021, 10:32 AM
Abhay
Abhay - avatar
+ 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
30th Aug 2021, 3:19 PM
Mehran
Mehran - avatar
+ 2
Mehran yes i figured that out , ty! By the way in second code of yours event is a window property and deprecated.
30th Aug 2021, 3:37 PM
Abhay
Abhay - avatar
+ 2
Mehran check the comment by odlint on my code
30th Aug 2021, 3:55 PM
Abhay
Abhay - avatar
+ 2
Abhay thanks.
30th Aug 2021, 4:08 PM
Mehran
Mehran - avatar
+ 1
Abhay can you refer me to a page that says "event" is deprecated?
30th Aug 2021, 3:49 PM
Mehran
Mehran - avatar