Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

New, more JS-like syntax #20

@friendlyanon

Description

@friendlyanon

The proposed syntax for private fields is absolutely disgusting, to simply put, it is confusing, is without prior art and very much alien to the elegant syntax JS has.

I must ask, why did you decide to use such an ugly syntax? Last I checked private had no use at all.
Combine that with the fact that we already in the process of adapting metaproperties, here is my proposal to you as to what an elegant syntax would look like:

class Counter extends HTMLElement {
  private xValue = 0;

  private get x() {
    return private.xValue; // !
  }
  private set x(value) {
    private.xValue = value; // !
    window.requestAnimationFrame(
      private.render.bind(this) // !
    );
  }

  private clicked() {
    private.x++; // !
  }

  constructor() {
    super();
    this.onclick =
      private.clicked.bind(this); // !
  }

  connectedCallback() {
    private.render(); // !
  }

  private render() {
    this.textContent =
      private.x.toString(); // !
  }
}
window.customElements.define('num-counter', Counter);

Reference:
function.sent meta property
new.target meta property

As much as I despise the idea of private fields, as I do believe this goes very much against the spirit of the open web and my love towards userscripts, at least make this abomination something pleasing to look at.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions