ES2015 example for event-target-shim

HTML

<script src="https://rawgit.com/mysticatea/event-target-shim/master/dist/event-target-shim.umd.js"></script>

<h1>ES2015 example for event-target-shim</h1>
<hr>
<p>See the console of devtools.</p>

JavaScript

const {EventTarget, defineEventAttribute} = EventTargetShim

// Define a derived class.
class Foo extends EventTarget {
    // ...
}

// Define `foo.onhello` property.
defineEventAttribute(Foo.prototype, "hello")

// Register event listeners.
const foo = new Foo()
foo.addEventListener("hello", (e) => {
    console.log("hello", e)
})
foo.onhello = (e) => {
    console.log("onhello", e)
}

// Dispatching events
foo.dispatchEvent(new CustomEvent("hello", { detail: "detail" }))