0

Can anyone explain the reason for this? Given that window.event is not defined anywhere and after this callback if you check window.event, it comes as undefined. I have checked this on Chrome, Safari and Firefox, the behavior is the same. This is also applicable for onmessage.

document.addEventListener("click", function(e) {
        console.log("event clicked: ", e); // PointerEvent
        console.log(window.event); // PointerEvent
    })

NOTE: Once you set window.event , then it doesn't behave like this.

Reason for this behaviour of the browsers

hopper01
  • 29
  • 4

1 Answers1

0

window.event is deprecated and should not be used.

It is left over from the very early days of JavaScript on the WWW when event handlers were attached using onclick and similar intrinsic event attributes instead of addEventListener.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335