Class literals: does "public" still make sense?

Kam Kasravi kamkasravi at yahoo.com
Sun Sep 25 20:31:05 PDT 2011


I see, so private declarations may go back to being defined at the class level - at least semantically - in order for the private name to be in scope 
across the class eg this[heath] referenced in Monster prototype methods: get isAlive(), Monster.set health(). 


________________________________
From: Brendan Eich <brendan at mozilla.com>
To: Kam Kasravi <kamkasravi at yahoo.com>
Cc: Mark S. Miller <erights at google.com>; Axel Rauschmayer <axel at rauschma.de>; es-discuss <es-discuss at mozilla.org>
Sent: Sunday, September 25, 2011 8:10 PM
Subject: Re: Class literals: does "public" still make sense?


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/63f83dac/attachment-0001.html>


More information about the es-discuss mailing list