-
Notifications
You must be signed in to change notification settings - Fork 3
Document differences from existing proposal #27
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
Comments
Thanks @bakkot for putting together this list. First, I want to be really clear about language: it is essential that we not use the term "private field" to talk about instance variables, because one of the primary goals of the proposal is to avoid conflating own properties and instance variables under a blanket concept "fields". A similar argument applies for the term "private methods".
We briefly had this in place, but it has been removed. (I just updated the rationale document to reflect the current status.)
That is correct.
They do. As in the private field proposal, everything inside of the class body has visibility of the hidden names defined in the class body.
Again, we use the term "hidden method". Any method (including accessors) can be
As is (I believe) the case with the current fields proposal, a TypeError will be thrown if the instance already "has" the instance variable. |
I get why this would be desirable, but I think it isn't something we can actually do. All TC39 has actual authority over is the syntax and semantics of the language, not how people refer to parts of it, and I guarantee people will continue talking and thinking about "public and private fields" no matter what language the proposal uses or how we try to teach it. I'm going to continue using the language myself in the context of this thread, since this list is intended to explain things to people who are familiar with the language of the old proposal, and since Thanks for the corrections and clarifications. Here's an updated list: Differences:
Similarities:
|
So in this proposal, hidden instance methods do not do a brand check, but hidden instance variables do? |
Hi @bakkot , great list. Thanks for gathering it together. I'll use it to briefly state my current positions and point to the issue where this was discussed in more depth. Despite the following criticisms, I am strongly in favor of this proposal.
See #7 . In the current state of this proposal {
var x; in one context would mean something completely different than {
var x; in another context. I find this terrible.
See #7 again Both I liked an earlier version that had hidden methods just be concise method syntax prefixed with The current proposal introduces a sigil, an overloading of the meaning of an existing keyword, and a new keyword. The alternative explained here introduces fewer new syntactic elements, but uses the introduced sigil more often. Would large numbers of people really find the first simpler than the second?
Awesome improvement!
This makes me uncomfortable, but I understand the reasons for this. I reluctantly agree.
Accessors also differ from methods in how they are invoked. |
Thank you all. I couldn't see anything in the rationale.md on this: Is it really a good idea to use I assumed skinny arrows would be used for non-lexically bound functions. 💯 |
Yes, we did consider this point, and we also considered "stealing" |
Seriously though, Noticed some of that here: #19 (comment) Ugh, I keep coming back to: do we really need privates in JS? I know, there are use cases, and it's cleaner than alternatives - but JS has made it this far w/o this stuff. One thing I'm really curious about:
|
Uh oh!
There was an error while loading. Please reload this page.
I missed at first glance that this proposal didn't include public fields, and I'm sure there's other things I'm missing too. I think that for the committee members who are familiar with the existing proposal - at least for me, anyway - it would be helpful to have a document detailing the differences in syntax and semantics.
EDIT: These lists are not entirely correct, please refer to updated list below instead.
Using the language of the old proposal, so where I say "private fields" I mean "the thing the old proposal calls private fields and the new one calls instance variables", here's my stab at a list of differences:
var x
instead of#x
hidden foo(){}
instead of#foo(){}
this->x
instead ofthis.#x
static {}
blocks({}->hiddenFoo())
would throw)Things that are similar:
methods, or accessors (edit: I guess static hidden methods are supported, looking closer)Things I am not clear on:
let o; class B { constructor(){ return o ? o : this; } } class D extends B { var x; constructor(){ super(); o = this; } } new D; new D;
do on the second invocation ofD
?The text was updated successfully, but these errors were encountered: