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";
    };
  }
}




-- 
    Cheers,
    --MarkM
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to