proposal-class-access-expressions icon indicating copy to clipboard operation
proposal-class-access-expressions copied to clipboard

Locking out metaproperties

Open Jamesernator opened this issue 5 years ago • 1 comments

By using the syntax class.<prop>, we effectively lock out the ability to add metaproperties for exposing things about classes that should be kept private.

For example in the decorators proposal I've mentioned the possibility of accessing the decorated and undecorated class using metaproperties (here). But one could imagine other cases such as private constructors, getting a list of applied decorators or other similar usages.

As such I think it would be better if instead of blocking the entire class. namespace, to instead use a single metaproperty hanging off class, e.g. class.current/class.original/etc

Jamesernator avatar Sep 20 '20 05:09 Jamesernator

One thing I do like about having just class on it's own (while I do see the downside of blocking the whole namespace), is that it is only one character longer than this.

class WithALongName {
  static #f = 1;
  static method() {
    this.#f; // unsafe to use `this` as could be called by static subclass
    class.#f; // safer with similar effort to read/write
    
    class.current.#f; // safe but same length as reading/writing:
    WithALongName.#f; // safe but verbose
  }
}

acutmore avatar Jan 15 '22 12:01 acutmore