tc39 / proposal-private-declarations

A proposal to allow trusted code _outside_ of the class lexical scope to access private state
https://tc39.es/proposal-private-declarations/
MIT License
25 stars 4 forks source link

Add `public #x` #5

Open Igmat opened 5 years ago

Igmat commented 5 years ago

We don't know what is private #x yet (I hope #4 will be answered soon), but it seems to be some kind of symbol.

It makes sense to have public #x notation in this case, doesn't it? I propose it to be kinda like shorthand for const x = Symbol(). But in this case, it have much more sense to have class-fields affected like in #1.

Examples:

public #x;
existingObj.#y = 1; // throws because #y isn't declared yet
const obj = {
    #x: 1,
    public #y: 1,
};
const otherObj = {
    public #x: 1, // shadows `#x` from outer lexical scope
    #y: 1, //  throws because #y isn't declared yet in this scope
};
public #x;
existingObj.#y = 1; // throws because #y isn't declared yet
class SomeClass {
    #x = 1;
    public #y = 1;
};
class SomeOtherClass = {
    public #x = 1; // shadowed `#x` not shared with `SomeClass`
    public #y = 1; // another `#y` not shared with `SomeClass`
};