Created
August 5, 2019 12:51
-
-
Save indreklasn/ce0912ae4fe3120ae7e2b3116697cbad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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