Re: [whatwg/dom] "Web developers are strongly encouraged to inste..." (Issue #1123)

@annevk @domenic 

Thanks for your responses.

I care deeply about that, and have been monitoring it for +3 years, as I use the already available "event" object in all my functions to capture the details of the event that bubbled up to call my functions.

Here's the type of code I write today, with 100% success rate : 

```
<div onclick="doSomething(5)">

function doSomething(number){
  console.log(event);
  console.log(event.target);
}
```

Please explain to me how I'm supposed to access the automatically created event in the new world? 

Below works by adding event in the function call, but isn't this equivalent to passing Window.event to my function? And the IDE is flagging that usage of "event" as deprecated, not sure if that's accurate. But to confirm, is this what we're supposed to do now? Or no. If so, I will contact JetBrains to have them resolve it .

```
<div onclick="doSomething(5, event)">    <-- The IDE is flagging this event as deprecated as well 

function doSomething(number, a){
  console.log(a);
  console.log(a.target);
}
```

Or if I try using the hard-coded "event" name in the signature hoping for it to be automatically filled by the browser doesn't work: 

```
<div onclick="doSomething(5)">

function doSomething(number, event){
  console.log(event);
  console.log(event.target);
}
```

Nothing comes through , and it blocks Window.event as the undefined argument takes precedence.

I could manufacture my own event:

```
<div onclick="doSomething(5, new Event('click'))">

function doSomething(number, a){
  console.log(a);
  console.log(a.target);
}
```

But here is missing all the details of the event as expected, including target, etc, but that's certainly not how it was designed to work.

Can you help me understand what exactly is deprecated here? How am I supposed to access the event that bubbled up and triggered the function call? 

Please look at the pain we are going through due to lack of clarity of what we're supposed to stop doing and start doing. 

https://stackoverflow.com/questions/16404327/how-to-pass-event-as-argument-to-an-inline-event-handler-in-javascript/57741298

Once I clarify it with you, I will go update my answer on stack overflow above for everybody to know. 

And if I need to contact my IDE I will open a ticket with them to stop marking it as deprecated in the correct scenario.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1123#issuecomment-1293603556
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1123/1293603556@github.com>

Received on Thursday, 27 October 2022 14:24:21 UTC