An "extend" operator is a natural companion to <|
rnystrom at google.com
Tue Jul 19 11:41:43 PDT 2011
On Tue, Jul 19, 2011 at 11:23 AM, Brendan Eich <brendan at mozilla.com> wrote:
> On Jul 19, 2011, at 11:07 AM, Bob Nystrom wrote:
> // "new" lets you declare members on new instances. these would presumably
> // invoked on the new object before the constructor body is run.
> numAttacks = 0;
> // declaring an instance property here mainly so you can document it.
> could be
> // useful later for guards or other annotations.
> The plain name; also looks like a useless expression-statement.
Yeah. :( Granted, it isn't even necessary so this corner case may not matter
much. I mentioned it because our earlier proposals have included a
declarative syntax for instance properties, even though it's mostly for
> Beyond this, I'm concerned that per-instance properties need initializers
> that use constructor parameters. So they ought to be initialized in the
Agreed. The ctor is where the real magic happens. Declaring instance
properties at the class level is just bonus. It would be useful for things
like having a place to hang a Closure-style type annotation comment, but
wouldn't be critical at runtime.
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.
Exactly. I do like the ability to declare and initialize per-instance
properties outside the constructor for properties that *don't* depend on
constructor arguments since it highlights that fact, but it isn't a key
> 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
> numAttacks: 0;
I'd worry that that's too close to the prototype: and class: section syntax
we're talking about adding. We use ":" so much already that I hesitate to
invoke it again.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss