rdking / proposal-class-members

https://zenparsing.github.io/js-classes-1.1/
7 stars 0 forks source link

`let static x` or `static let x` #7

Closed hax closed 5 years ago

hax commented 5 years ago

I would prefer static let x 😅

Actually, I'm not sure we need static let/const, it seems normal let/const outside class + static block (which have separate proposal) already provide the functionality.

rdking commented 5 years ago

I thought about putting static before let, but that wouldn't make visual sense. Where let is the beginning of a variable declaration (driving home the point that these are not properties), static is a modifier to a declaration that usually only applies to class properties.

What you get with let/const static is a variable that is attached to the constructor and only accessible within the class lexical definition. Even static block will not make this kind of encapsulation possible. Besides, from what I could see, static blocks are meant to provide something akin to friend in C++. It allows for the definition of an object that is separate from the class but has privileged access to the class's internals.

hax commented 5 years ago

After second thought, I think maybe let static is a little better...