If we are to encourage the web to have useful patterns, we should make those patterns re-usable. Currently, people always make a new event pattern because the existing event pattern (in browsers) is always limited only to DOM elements, and not all JavaScript code is tied strictly to DOM (in the browser, we’re not even talking about Node).
For example, the following doesn’t work, but it should:
class Foo extends window.EventTarget {
constructor() {
super()
console.log(this)
}
}
new Foo
It throws an error:
Uncaught TypeError: Illegal constructor
It would be great to be able to use .addEventListener()
et al with other things beside just DOM elements.