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

Why no literal privates? #115

Closed
Lcfvs opened this issue Sep 9, 2020 · 2 comments
Closed

Why no literal privates? #115

Lcfvs opened this issue Sep 9, 2020 · 2 comments

Comments

@Lcfvs
Copy link

Lcfvs commented Sep 9, 2020

Sorry but I don't see a topic about that point and I post on this repository because the merged one is about classes.

Is there any reasons to not consider something like this?

const o = {
  #a: 123,
  get a () {
    return this.#a
  }
}

Imho, it can be considered like

const o = new class {
  #a: 123;
  get a () {
    return this.#a
  }
}

Is there a problem about it?

@bakkot
Copy link
Contributor

bakkot commented Sep 9, 2020

Copying my answer from here:

In part just because of the history of the proposal: classes are the place where private fields were most obviously important (since you cannot easily substitute a closure for the same effect) and where the semantics were the most straightforward to reason about.

However, there's a followup proposal which would allow you to declare a private field in any scope and then use it in object literals: https://github.com/tc39/proposal-private-declarations

@Lcfvs
Copy link
Author

Lcfvs commented Sep 9, 2020

Ok, thanks.

@Lcfvs Lcfvs closed this as completed Sep 9, 2020
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

2 participants