[whatwg/dom] Make it easier to dispatch custom events (#483)

It would be easier to read and write the dispatching of Custom Events if they could be created within `dispatchEvent`.

```
cancelled = !EventTarget.dispatchEvent((Event or DOMString), customEventInit);
```

### Example:

Clicking a button fires a custom `filter:results` event from a container:

```js
buttonEl.addEventListener('click', () => {
  /* maybe prepare stuff */

  containerEl.dispatchEvent('filter:results', {
    detail: filterEl.value
  });
});
```

This small change makes a very readable difference for me. It would otherwise be:

```js
buttonEl.addEventListener('click', () => {
  /* maybe prepare stuff */

  containerEl.dispatchEvent(new CustomEvent('filter:results', {
    detail: filterEl.value
  }));
});
```

I struggle to quantify this, but it gets difficult for my eyes to follow functions directly within other functions, namely due to the touching `))`. Expanding them into new lines gains readability between the functions and constructors, but sacrifices the “paintstroke” readability of the actual “thing” I’m trying to accomplish.

I’ll completely understand if you find this request silly and my eyesight to be the real problem here. I earnestly felt like there really might be a advantage to many others if we ditched the constructor when dispatching custom events.

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

Received on Thursday, 27 July 2017 00:48:57 UTC