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

Brendan Eich brendan at mozilla.org
Mon Jan 23 13:34:43 PST 2012


> Gavin Barraclough <mailto:barraclough at apple.com>
> January 23, 2012 1:22 PM
> On Jan 23, 2012, at 1:11 PM, Brendan Eich wrote:
>
> Ah, that's the detail that I'd missed! - if private names will be 
> ignored if they are not to the right of @, then presumably my example 
> *would* result in at least a reference error, since 'x' would not in 
> scope in 'getX' (unless of course x resolves to the global object...).

Wait, your example was:

{
   private x:
   o.setX = function(x) {
     @x = x;
   }
   o.getX = function() {
     return x; // should be 'return @x;'
   }
}

You have private x in the private @-scope chain of both of those 
function expressions.

>  I was wrong in thinking that getX would return the private name? – if 
> so, this sounds good to me!

You were wrong in the middle alternative I think we skipped too quickly 
-- that x is unbound. We'd need a way to reflect from @-scope into value 
expression domain. The old private names proposal used #. as a prefix.
>
> Do we want there to be a way to be able to get to a private name 
> object declared by 'private foo;' syntax, or if developers want to get 
> their hands on a private name objects that they can pass around should 
> they just be calling Name.create directly?

I see no problem with an explicit reflection operator, so e.g. getX 
could say return @x or @(x) -- assuming we don't that syntax for 
something else. Perhaps there is better syntax, but the point is we can 
make this require an explicit operation.

/be



More information about the es-discuss mailing list