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

Andreas Rossberg rossberg at google.com
Mon Jan 23 02:10:04 PST 2012


On 23 January 2012 01:31, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>
> 2)  elimination of arbitrary expression as direct keys in object literal
> property definitions:
>
> The current "computed property keys" proposals allows things like:
>
> for (var n=0;n<10;) {
>    a.push( {
>       ["prop"+n]: n++
>    });
> }
>
> Do we really need to support this sort of computed property name definition?

If we are going for the customizability of [] that you were proposing,
then, yes, I think this form of literal still makes a lot of sense, as
a way to write custom collection literals. E.g.

let m = Map <| { [1]: a, [2]: b }

It would simply expand to respective assignments.

>  If so, we could probably allow something such as:
>
> for (var n=0;n<10;) {
>    a.push( {
>      @("prop"+n): n++
>    });
> }

Not sure about this particular example, but I reckon that you might
want to write something like

  @(M.a)

where `M' is a module that exports a private name `a'. This applies to
dot notation as well as object literals:

  let o = { @(M.a): 4 }
  o.@(M.a)

> 3) should @foo as a primary expression be interpreted as this. at foo

That seems irregular and confusing indeed.

/Andreas


More information about the es-discuss mailing list