Is class syntax really necessary ?

Brendan Eich brendan at mozilla.com
Mon May 23 10:41:31 PDT 2011


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
>  }
> };
> 
> Allen and I have discussed this before, so it's not a surprise, but I'm worried that some proposals might omit fixing this on their todo list.

That's a good (C) but I do not see it addressed. Indeed Bob Nystrom counted occurrences in one codebase and found default property values set in class prototypes.

Your point seems to be that mutable (object) default values are a mistake, and I tend to agree. But how to exclude this option? Just adding sugar won't prevent such mistakes, indeed it could make the mistake more likely, depending on ergonomics and more imponderable user factors.

Where and how does the current proposal address (C)?

/be


> 
>> Can we agree that these are problems to be solved, if not by classes then by other APIs or special forms?
>> 
>> /be
>> 
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
> 
> --
> Alex Russell
> slightlyoff at google.com
> slightlyoff at chromium.org
> alex at dojotoolkit.org BE03 E88D EABB 2116 CC49 8259 CF78 E242 59C3 9723
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list