I noted some open issues on "Classes with Trait Composition"

Mark S. Miller erights at google.com
Wed May 18 17:51:03 PDT 2011

On Wed, May 18, 2011 at 5:17 PM, Bob Nystrom <rnystrom at google.com> 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";

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110518/553b29e7/attachment-0001.html>

More information about the es-discuss mailing list