On Jul 19, 2011, at 11:23 AM, Brendan Eich wrote:

> On Jul 19, 2011, at 11:07 AM, Bob Nystrom wrote:
> 
>> // "new" lets you declare members on new instances. these would presumably be
> 
>> // invoked on the new object before the constructor body is run.
>> new:
>>   numAttacks = 0;
>>   // declaring an instance property here mainly so you can document it. 
>> could be
>>   // useful later for guards or other annotations.
>>   name;
> 
> The plain name; also looks like a useless expression-statement.

When we talked some people pretty strongly felt that it was very desirable to 
be able to explicitly declare the intended per instance properties.  In 
addition to document purposes such declaration might, for example, be used for 
things like linting for this.mispellings in the body of the function.  Such 
explicit  declarations are probably essential if they are private properties.  
But I don't see any problem with requiring inclusion of an initial value, even 
it it is going to be |undefined.|

> 
> Beyond this, I'm concerned that per-instance properties need initializers 
> that use constructor parameters. So they ought to be initialized in the 
> constructor.
> 
> Whether they can be declared outside the constructor is a separate issue. 
> Perhaps if they have constant or constructor-invariant initializers, they can 
> be initialized where declared too.

This seemed to be a big issue in the past that caused a lot of thrashing about 
how to put such declarations inside the constructor.  Backing off from that 
requirement would be helpful.

> 
> But declarations should look different from expressions. The alternative we 
> keep returning to is the property assignment sub-grammar of object literals, 
> which would want
> 
>   new:
>     numAttacks: 0;
> 
> with a semicolon not a comma.

some thoughts -- why does the punctuation following the new (or class or 
prototype or whatever).  For example, what about

   --new--
     numAttacks: 0;

that looks more distinctly like a section break and different from a property 
name (and otherwise how would one define a property name new or class or 
prototype or private?)

Also, why ; instead of , like in object literals  (alternatively could we allow 
use of ; as a separator in object literals).  It seems desirable to have 
consistency of property definitions between object literals and class 
declarations.


Allen
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to