Rob's garden / notes / note

Note

#TIL you can make any #JavaScript class emit and listen to events by subclassing EventTarget

class Geoff extends EventTarget() {
  hello() {
    this.dispatchEvent(new CustomEvent("hello");
  }
}
const person = new Geoff();
person.addEventListener("hello", e => {
  console.log("Wazzup!");
})
person.hello()