Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Created August 5, 2019 12:51
Show Gist options
  • Save indreklasn/ce0912ae4fe3120ae7e2b3116697cbad to your computer and use it in GitHub Desktop.
Save indreklasn/ce0912ae4fe3120ae7e2b3116697cbad to your computer and use it in GitHub Desktop.
class Counter extends HTMLElement {
#xValue = 0;
get #x() { return #xValue; }
set #x(value) {
this.#xValue = value;
window.requestAnimationFrame(this.#render.bind(this));
}
#clicked() {
this.#x++;
}
constructor() {
super();
this.onclick = this.#clicked.bind(this);
}
connectedCallback() { this.#render(); }
#render() {
this.textContent = this.#x.toString();
}
}
window.customElements.define('num-counter', Counter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment