title: Dispatch event with data
body: <p>I'd like to dispatch an event that will pass some data to any event listeners that listen on that event.</p>
  
  <p>Considering a function that fires an event:</p>
  
  <pre><code>function click() {
    const x = 'foo'
    document.dispatchEvent(new CustomEvent('clicked'))
  }
  
  click()
  </code></pre>
  
  <p>How can I pass custom data to the event listener?</p>
  
  <pre><code>document.addEventListener('clicked', function(e) {
    console.log(x) // logs "foo"
  })
  </code></pre>