Unified class features:
A vision of orthogonality
Daniel Ehrenberg
Guiding example
class Counter extends HTMLElement {� clicked() {� this.x++;� window.requestAnimationFrame(this.render.bind(this));� }�� constructor() {� super();� this.onclick = this.clicked.bind(this);� this.x = 0;� }�� connectedCallback() { this.render(); }
�� render() {� this.textContent = this.x.toString();� }�}�window.customElements.define('num-counter', Counter);
Private fields and method
class Counter extends HTMLElement {� #x = 0;�� #clicked() {� this.#x++;� window.requestAnimationFrame(this.render.bind(this));� }�� constructor() {� super();� this.onclick = this.#clicked.bind(this);� }
�� connectedCallback() { this.render(); }�� render() {� this.textContent = this.#x.toString();� }�}�window.customElements.define('num-counter', Counter);
Decorators
@defineElement('num-counter')�class Counter extends HTMLElement {� @observed #x = 0;�� @bound� #clicked() {� this.#x++;� }�� constructor() {� super();� this.onclick = this.#clicked;� }
� connectedCallback() { this.render(); }�� @bound� render() {� this.textCountent = this.#x.toString();� }�}
Dimensions