On Wed, May 18, 2011 at 5:51 PM, Mark S. Miller <[email protected]> wrote:
> On Wed, May 18, 2011 at 5:17 PM, Bob Nystrom <[email protected]> wrote: > >> I believe it would be something like: >> >> class Ctor { >> public method() { >> return "own property"; >> } >> >> method() { >> return "instance property"; >> } >> } >> >> By default, members within a class body are declared on the prototype. >> Prefixing it with public places it on the new instance. Using public for >> this isn't carved in stone yet, but <some keyword> means "place the >> member on the new instance" and that prefix can be applied to any kind of >> member: method, variable, constant, etc. >> > > Not quite. Per-instance member initialization only happens in the > constructor, because the values of per-instance properties is generally data > dependent on constructor parameters. The "public" (or whatever) and > "private" declarations only prefix ForwardDeclarations, which are generally > just comma separated lists of identifiers. The initialization in the > constructor happens in the traditional ES5 imperative manner. Also, the > public list is optional. It serves only a documentary purpose. So.... > > class Ctor { > public method; // optional forward declaration of own property > > method() { > return "instance property"; > } > > constructor() { > this.method = function() { > return "own property"; > }; > } > } > Ah, OK. While it isn't necessary, it would be really convenient to be able to create per-instance properties by providing an initializer in the class body if those properties don't depend on "this" or ctor params: class Point { public x = 0, y = 0; } let p = new Point(); p.x; // 0 - bob
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

