简体   繁体   中英

keyboard EventListener in javascript

can anyone explain me how the argument e is captured and passed as a function callback which displays the keyboardEvent Object in console. Same this can be acheived by using

() => console.log(event);

so why do we do like this

 (e) => console.log(e);
document.addEventListener("keydown", e => {
console.log("key Pressed");
console.log(e);
});

Event object exists in Spyglass based browsers but doesn't exist in Mosaic based browsers as a scriptable object, or at least as an accessible object.

For this reason Mosaic (which was killed by The Project "Mosaic Killa"), from where we now have Mozilla for short, which in that process developed Netscape Navigator , had to arbitrarily pass the event object as a value of a function argument .

So, in order to be compatible with both worlds, the arbitrary event assignment to the first provided function argument has become mandatory for both.

Although you can still call for the event object in the Spyglass line of browsers, if that's your exclusive target clientele on some intranet app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM