Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative: Remove own restriction on PrivateName #164

Merged
merged 1 commit into from
Nov 2, 2018

Conversation

littledan
Copy link
Member

Given the Stage 3 resolution on the static class features issue,
static private is now permitted. This patch removes the corresponding
restriction for decorators, which was probably left in as a relic of
that issue.

@nicolo-ribaudo
Copy link
Member

Can the placement be "prototype"?

@littledan
Copy link
Member Author

@nicolo-ribaudo I believe we should permit this, for the same reason as in #57 .

@nicolo-ribaudo
Copy link
Member

Before #57, "prototype" was already disallowed (also, it is indicated as disallowed in #16 (comment)). I understand why static private fields should be allowed (static #x is valid), but I don't get why also prototype private fields.
Also, having them on the prototype gives the false expectation that they should also be accessible from the instance, while they aren't (unless I'm wrong):

class Foo {
  @moveToPrototype
  #foo = {};

  @moveToPrototype
  bar = {};

  getFoo() { return this.#foo; }
  getBar() { return this.bar; }
}

new Foo().getBar() === new Foo().getBar(); // Works, because getBar gets this.__proto__.bar;
Foo.prototype.getFoo() === Foo.prototype.getFoo(); // Works, because it gets Foo.prototype.#foo;
new Foo().getFoo() === new Foo().getFoo(); // Throws, because it doesn't get this.__proto__.#foo but this.#foo

function moveToPrototype(desc) {
  desc.placement = "prototype";
}

@littledan
Copy link
Member Author

That's right, they wouldn't be accessible from the instance. Decorator authors would be expected to understand exactly how private works.

@littledan
Copy link
Member Author

littledan commented Nov 2, 2018

Any other opinions on whether we should accept prototype private? Given the concern raised here, I'm thinking to make a more minimal change, to just permit static private, which would be a pure bug fix given the Stage 3 private static proposal.

Edit: Pushed more minimal change.

Given the Stage 3 resolution on the static class features issue,
static private is now permitted. This patch removes the corresponding
restriction for decorators, which was probably left in as a relic of
that issue.
@littledan littledan force-pushed the non-own-private-name branch from dafca1d to 1ae4442 Compare November 2, 2018 10:07
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss the prototype placement in a new issue.

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

Successfully merging this pull request may close these issues.

2 participants