On Sep 29, 2011, at 3:20 PM, Russell Leggett wrote:

> On Wed, Sep 28, 2011 at 10:40 PM, Oliver Hunt <[email protected]> wrote:
> 
> Given our apparent desire to have a declarative syntax i don't see why 
> something akin to:
> 
> class Foo {
>    var bar; // default value -> undefined
>    var wibble = 5; // initialised fields desugar to statements at the head of 
> the constructor
>    const wiffle; // read barrier on uninitialised
> 
>    function someMethod(..) {
>         this.bar = foo; // could have a short hand for this.property
>    }
> 
>    constructor (bar, wibble) {
>        // extra typing due to the removal of horrible punning
>        // but "public bar = bar" or whatever that syntax was is longer
>        // than this.bar
>        this.bar = bar;
>        this.wibble = wibble;
>    }
> }
> 
> function's get shoved on to the prototype chain, and fields go on the 
> instance, inheritance follows reasonably sensibly from that.  Remove the 
> declarative field definitions and you have essentially got python's class 
> model, which seems to be well accepted by a wide array of people, otherwise 
> the question becomes one of how much you want to lock down the resultant 
> object shape.
> 
> --Oliver
> 
> 
> Hi, just a voice from the peanut gallery - of the proposals going on right 
> now, I really like this proposal a lot. Perhaps it is just my experience with 
> Java, but this feels like an intuitive class syntax that also stays feeling 
> like JavaScript. I like that it doesn't introduce a new keyword "public" 
> which I especially didn't like because there was no "private" keyword.

This syntax is awfully familiar from original-JS2/ES4 (Waldemar's 1999-2003 
effort) and the 2006-2008-era ES4.

There are some on the committee who object to 'var' in particular; others 
object to using scoped binding forms to define properties in (default mutable) 
objects. We can go around this block again, though.


> In regards to private fields/methods in classes, I did also have a thought 
> that perhaps you could use proxies to provide a peephole view of a class 
> instance.

Proxies are too heavyweight. We have private name objects:

http://wiki.ecmascript.org/doku.php?id=harmony:private_name_objects

which can be implemented very cheaply, and our current consensus for private in 
classes is that you would bind module- or block-scoped consts to private names, 
one per class-private instance variable, and then use them via this[priv] = 
initialValue, Object.create, Object.defineProperty, etc.

/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to