Is class syntax really necessary ?

Kam Kasravi kamkasravi at yahoo.com
Mon May 23 11:34:23 PDT 2011


If one has a class proposal with the prerequisite examples and grammar specification, how does one propose this with a possible goal of an alternate strawman? 


On May 23, 2011, at 11:25 AM, Bob Nystrom <rnystrom at google.com> wrote:

> 
> 
> On Mon, May 23, 2011 at 10:41 AM, Brendan Eich <brendan at mozilla.com> wrote:
> On May 23, 2011, at 10:03 AM, Alex Russell wrote:
> 
> >> (A) the boilerplate needed to set up a sub-prototype object with correct constructor property, and
> >>
> >> (B) the pain of doing correct super calls by hand.
> >
> > I hope we can add the hazards of incorrectly adding mutable state to a prototype and not an instance to this list. I.e., many people get this wrong:
> >
> > function C(){
> >  // should include:
> >  //   this._list = [];
> > }
> > C.prototype = {
> >  _list: [],
> >  addToList: function(item) {
> >    this._list.push(item);    // logic error!
> >    // side-effects here
> >  }
> > };
> 
> There's two bugs there:
> 1. Not creating this._list in the ctor.
> 2. Creating one on .prototype.
> 
> If bug #1 is fixed, there's no sensible reason to ever define _list on the prototype since it would always be shadowed.
>  
> > Where and how does the current proposal address (C)?
> 
> One thing I'd like the proposal to support, which it doesn't currently, is initializers on instance property declarations. Then you could do:
> 
> class C {
>   public _list = [];
> }
> 
> With that, you'll correctly get a new _list on each instance of C when it's created.
> 
> - bob
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110523/4310dabe/attachment-0001.html>


More information about the es-discuss mailing list