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

Brendan Eich brendan at mozilla.org
Sat Jan 21 12:07:36 PST 2012


This was already proposed. See the whole strawman, but in particular 
these sections:

http://wiki.ecmascript.org/doku.php?id=strawman:private_names#the_private_declaration
http://wiki.ecmascript.org/doku.php?id=strawman:private_names#private_declaration_scoping
http://wiki.ecmascript.org/doku.php?id=strawman:private_names#private_declarations_exist_in_a_separate_name_space_parallel_to_the_variable_binding_environment

The last really was too much for some folks. It makes the meaning of an 
identifier after . or before : in an object literal depend on a binding 
declaration, possibly far above.

We could revive this, but deferring it and simplifying led to

http://wiki.ecmascript.org/doku.php?id=harmony:private_name_objects

which is in ES6.

/be

> Herby Vojčík <mailto:herby at mailbox.sk>
> January 20, 2012 3:34 PM
> Hello,
>
> since @-prefixed syntax to access private-named properties seems to 
> win in the private grounds (and it is good thing), I'd like kill two 
> birds with one stone:
>  - private keyword seemed to lose its role
>  - to access property via @foo, I must 'let foo = Name.create()' first
>
> So let us allow:
>   ... {
>     private foo, bar;
>     ...
>     agent. at foo = ...;
>     ...
>     more uses of @foo and @bar
>     ...
>   }
> in imperative (code-containing, semicolon-delimited) blocks and
>   ... {
>     private [foo, bar],
>     ...
>     @foo: Date.now(),
>     @bar: cowboys.length,
>     ...
>     aMethod () {
>       ... use @foo and @bar
>     }
>   }
> in declarative (data-describing, comma-delimited) blocks.
>
> In both cases let it be the declaration of (one-time lexical 
> block-local) private names foo and bar. For any curly block. Without 
> need to define these singletons explicitly and wrap them so they are 
> only visible where due,
>
> Herby
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list