Class literals: does "public" still make sense?
Brendan Eich
brendan at mozilla.com
Sun Sep 25 15:07:20 PDT 2011
On Sep 25, 2011, at 2:20 PM, Axel Rauschmayer wrote:
>> We did not agree to drop the private declaration syntax at the July TC39 meeting. Perhaps my understanding of our agreement then does not match Marks?
>>
>> What we agreed to drop was the private(this) straw syntax in the classes proposal, in favor of this[x], this[y], for private-declared private name objects x and y.
>
> For public properties one has two options:
> 1) this.foo = foo;
> 2) public foo = foo;
>
> Using Mark’s terminology, #1 is imperative, #2 is declarative.
>
> Private properties would be declared like this (right?)
> this[myPrivateName] = someData;
>
> This is imperative (like #1), there is no way to do this declaratively (like #2).
At some point, we had
private myPrivateName;
in the constructor body as the way to declare a private instance variable.
It's a bit odd to allow an initializer _I_ in such a declaration and have it mean this[myPrivateName] = _I_. This may be the glitch.
Even with the @ syntax that's not on the boards, a private x, y; declaration would not include the @ sigil, which seemed verbose yet inconsistent.
What's more, often the ctor takes parameters that one wants to initialize the same-named privates. This led to discussion here (and support in CoffeeScript prefiguring that discussion) of:
class Point {
constructor(@x, @y) {}
...
}
as short for
class Point {
constructor(x, y) {
private x = x, y = y;
}
...
}
It seems to me we'll quickly run into user push-back if we do not private any private instance variable sugar, not even for declaring and initializing from ctor parameters. But we can "go there" if it's the best way to make progress.
/be
>
> I think it’s a clean solution and am not sure how much private properties are needed for non-security-critical applications. But it does not give you the automatic “const-ification” of “public”.
>
> --
> Dr. Axel Rauschmayer
> axel at rauschma.de
> twitter.com/rauschma
>
> Home: rauschma.de
> Blog: 2ality.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110925/41a52dff/attachment.html>
More information about the es-discuss
mailing list