JSFiddle - React, Tailwind, and code Playground
JavaScript
class MyButton extends HTMLButtonElement {
constructor() {
super();
for (let prop of Object.getOwnPropertyNames(this.constructor.prototype)) {
if (prop.indexOf("on") === 0) {
console.log("Adding a " + prop + " listener");
this.addEventListener(prop.substring(2).toLowerCase(), this.constructor.prototype[prop]);
}
}
this.textContent = "Click me";
}
onClick() {
console.log("Wohoo");
}
}
customElements.define("my-button", MyButton, { extends: "button" });
document.body.append(new MyButton);