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

Private Properties Syntax #6

Closed
pumano opened this issue Jun 17, 2017 · 8 comments
Closed

Private Properties Syntax #6

pumano opened this issue Jun 17, 2017 · 8 comments

Comments

@pumano
Copy link

pumano commented Jun 17, 2017

I have opinion against syntax for private properties and methods in this proposal.

Many languages have keywords private, protected, public. I suggest to add that keywords against # syntax. It's looks like you guys reinventing the wheel, but we have that syntax many years in languages like Java or C++ or PHP etc.
And making JavaScript with "something" new is harm to JavaScript. I think Javascript need to be more closer to other languages like Java or C# or TypeScript (where we have private/protected/public modificators). And don't create your "own" things.

@bakkot
Copy link
Contributor

bakkot commented Jun 17, 2017

See the FAQ for private fields.

In short: of course we started out trying to make it work with the same syntax used in other languages. That turns out not to work.

@littledan
Copy link
Member

At the next TC39 meeting, I'll raise this concern again. However, I'm not sure how much more ground there is to cover here--this has already been thoroughly discussed in the private fields issues.

@dinoboff
Copy link

dinoboff commented Oct 5, 2017

@littledan I understand why access to private fields needs a specific syntax, but that's not true for the declaration. Was the possibility of having a keyword like private x used to declare a private field and using #x only to access it discussed?

@bakkot
Copy link
Contributor

bakkot commented Oct 5, 2017

@dinoboff See the FAQ for private fields.

@dinoboff
Copy link

dinoboff commented Oct 5, 2017

So private x would lead to bad assumption. Can't an other keyword be used instead?

@bakkot
Copy link
Contributor

bakkot commented Oct 5, 2017

We discussed the possibility of an additional keyword for declarations at TC39. Ultimately, we were pretty firm that the declaration should include the #, so that declaration would mirror use and to encourage the mental model that the # is part of the field name. At that point, we felt an additional keyword would just be additional noise for not much benefit.

@monolithed
Copy link

monolithed commented Oct 16, 2017

In my opinion the sigil # looks like a syntactic noise and I'd to see something more compatible with TypeScript and other languages.

class Foo {
   private x = 1;

   public y () {
        return this->x;
   }
}


let foo = new Foo();

foo.y(); // 1

Why not to use the arrow -> instead of the dot .?

@ljharb
Copy link
Member

ljharb commented Oct 16, 2017

@monolithed for your first question, please read the FAQ (this is also answered about 3 comments up)

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