shortcuts for defining block-local private names, plays nicely with @foo syntax

Herby Vojčík herby at
Sun Jan 22 12:34:43 PST 2012

Brendan Eich wrote:
> I suspect your very complicated translation with __prvTable__ etc. is
> intended to hoist private somehow, once per declaration in source rather
> than once per evaluation of declaration. That's too restrictive, since

Exactly. By design.

> private declarations can be placed in outer blocks or closures for
> singleton naming, or moved into inner constructor-like functions for
> per-instance private names.

I proposed private to really only do the conventional per-source 
singleton aliasing (I dubbed 'const foo = perSourceTable[index]' 
aliasing for this discussion).

The motivation for this is exactly the "can be placed in outer blocks or 
closures". My proposal for 'private' is precisely and only to create 
conventional way to do these singletons without need for those annoying 

Maybe I should include the example to illustrate how hard and 
inconcievable it is to create such singleton for use in a few { levels 
deeper, going there and back, creating them more for many nested levels 
in one outer place, and so forth, but I believe you can imagine.

> Users should be able to declare class-private and instance-private
> names, in other words.

These cases do not need any special syntax. They can use const foo = 
Name.create(). It is very little hassle. I proposed 'private' only for 
singletons, because for them the convenience is really useful.

Use singleton in class block scope.

> Your block examples, which I modified, are not complete enough to judge
> what's wanted. By asserting singleton private name per source
> declaration you are deciding prematurely and overconstraining the
> feature. Let the user put the block or closure at the right inner or

It was meant as a convenience only for singletion, as they are the hard 
case. The other cases are easy without need for help from 'private'.

So user can put the local case there, by normal means.
Or he can put the hard case (singletion with wrapper) with conenient 

> outer level and declare there. There are an arbitrary number of
> generative layers (generations): class static private, class instance
> private, inner closure private, etc. etc.

And I say (and hopefully I am not mistaken) that those runtime-local are 
easy to do by playing with let, const and Name.create(); and those 
lexically-local are hard so the convenience is placed especially for them.

Also, I'd say, the semantics of private can then be straightforward: for 
_any_ {...} block, the private key is only created once and visible only 
in the block. Never mind what block will it be; you have the spatially 
local temporally shared key for your use.

> /be


More information about the es-discuss mailing list