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

What about `static.foo` instead of `class.foo`?

Open hax opened this issue 5 years ago • 3 comments

It seems static.foo may be a little bit easier to understand because it just map the static foo declaration.

hax avatar Jul 20 '20 21:07 hax

Another benefit may be it could provide a way to refer the class, for example new static.

hax avatar Jul 20 '20 22:07 hax

Concerns brought up around this are that static is a valid identifier in sloppy mode, and is currently an error inside class bodies, since they're auto-strict:

let static = { x: 1 };
class C {
  static x = 2;
  static y = static.x;
}
C.y // 1, 2, or "threw before evaluating this line"?

This currently throws; with this proposal using static., it would produce 2, but a user might expect it to produce 1, which would be confusing.

ljharb avatar Jul 20 '20 22:07 ljharb

Yeah, it bring ambiguity in sloppy mode, but I would argue that it won't be worse than the similar issues of await/yield. 😂

hax avatar Jul 21 '20 02:07 hax