Class literals: does "public" still make sense?
Brendan Eich
brendan at mozilla.com
Sun Sep 25 20:10:25 PDT 2011
On Sep 25, 2011, at 3:12 PM, Kam Kasravi wrote:
> class Monster {
> // The contextual keyword "constructor" followed by an argument
> // list and a body defines the body of the class’s constructor
> // function. public and private declarations in the constructor
> // declare and initialize per-instance properties. Assignments
> // such as "this.foo = bar;" also set public properties.
> constructor(name, healthvalue) {
> public name = name;
> module name from "@name";
> private health = name.create();
No, that's silly. If there is to be private declaration syntax, it should generate the private name, class-private (shared among instances). What you just spelled out wants 'const' not 'private', but hoisted to an outer closure. The way you wrote it, each constructor call would make a new and unique private name, so you'd get instance-private instance variables, not class-private.
> this[health] = healthvalue;
This part is what we agreed to in July.
/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110925/896616fa/attachment.html>
More information about the es-discuss
mailing list