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

Backwards compatibility issue with private # sigil. #128

Closed
JorisBlanken opened this issue Sep 12, 2018 · 7 comments
Closed

Backwards compatibility issue with private # sigil. #128

JorisBlanken opened this issue Sep 12, 2018 · 7 comments

Comments

@JorisBlanken
Copy link

JorisBlanken commented Sep 12, 2018

Consider the following class definition:

class Example {

    constructor(x){
        this['#x'] = x;
    }

}

Currently this value can be accessed from outside the instance:

let example = new Example(5);
console.log(example['#x']); // Prints 5

If the # sigil syntax follows current member referencing standards, such that object members can both be accessed directly using the dot operator (if a valid identifier) and using a string literal, then currently accessible members can become inaccessible when this proposal is implemented.

@jkrems
Copy link

jkrems commented Sep 12, 2018

Afaik the proposal doesn't affect this syntax. The code above will still work after this proposal is implemented. this.#x and this['#x'] are independent values.

@ljharb
Copy link
Member

ljharb commented Sep 12, 2018

Indeed, this isn't an issue precisely because private fields can only use dot access.

@bakkot
Copy link
Contributor

bakkot commented Sep 12, 2018

See faq.

@MichaelTheriot
Copy link

MichaelTheriot commented Sep 14, 2018

This may not be an issue but it is clear that intuition led the poster to suspect this should work due to # syntax, which is an issue?

@ljharb
Copy link
Member

ljharb commented Sep 14, 2018

I don’t see it as an issue, i see it as something someone will have to learn once.

@MichaelTheriot
Copy link

I respect that is consensus of TC39. I think developer consensus would be valuable too.

@littledan
Copy link
Member

I don't really see this as a compatibility issue, as it's not about how existing code works. Unfortunately, this syntax is sort of at odds with privacy itself; we have considered other syntaxes like this.#['x'], but ultimately decided it was unnecessary (you can just use an object or map in a private field for the same functionality). At this point, implementations are moving forward with the proposal in this repository; see the README for details.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants