usable enough private names (was: Re: Using Object Literals as Classes)

Domenic Denicola domenic at domenicdenicola.com
Fri Mar 16 14:24:45 PDT 2012


Yes, this looks pretty solid, although I can't remember seeing it anywhere.

(Sorry for the top-posting; my webmail doesn't want to add the >'s for me so I figured this is better than the alternative.)
________________________________________
From: Herby Vojčík [herby at mailbox.sk]
Sent: Friday, March 16, 2012 17:20
To: Domenic Denicola
Cc: Russell Leggett; Kevin Smith; es-discuss
Subject: usable enough private names (was: Re: Using Object Literals as Classes)

Domenic Denicola wrote:
> Just to contribute to this... er... fun-thread...
>
> My team uses the closure pattern for our "classes" (i.e. no prototype
> methods at all), since we value encapsulation. I can't imagine we're alone.
>
> So any class solution that doesn't fully incorporate private names (e.g.
> by making them awkward via manual Name.create(), etc.) will leave that
> audience behind, still using closures and ignoring any new class sugar.

Is the current (the last winning alternative afaicr) state good enough
for you?

In a few words:

   private x,y;

will be desugared to

   const x = Name.create(), y = Name.create();

So you would need to write your code as:

module ... {
   ...
   private foo, bar;
   ...
   class Alpha .... {
     ... uses names foo, bar in constructor and methods
   }

   ... maybe use the same name in subsequent classes and functions
}

Herby




More information about the es-discuss mailing list