return when desugaring to closures

Ingvar von Schoultz ingvar-v-s at comhem.se
Sat Aug 23 08:04:17 PDT 2008


Felix wrote:
> Ingvar von Schoultz wrote:
>> ...(but restricted to returned values). Also, my brain wants to
>> allow the following, or at least reserve as a future possibility...
>>
>>          var {a: x, b: y+z} = fn();
> 
> your form confuses me a lot, because it's not clear to me where 'y' and 
> 'z' are coming from.  what if the thing returned by fn() doesn't have a 
> 'y', is it going to pull 'y' from the lexical scope, or is it going to 
> use 'undefined' for 'y'?

That's what I meant by "restricted to returned values": I would
expect that the lexical scope would not be visible.

> the es-harmony form
>    var {x: a, y: b} = fn();
> makes intuitive sense to me because the thing on the left is a 
> pattern-matching template.  I'm saying that I expect the rhs object to 
> have that shape, and if the shape does match, pull out values from it.

Thanks for the description, it helps.

Is this the actual semantics? Does it require a matching shape
and throw an error otherwise?

-- 
Ingvar von Schoultz



More information about the Es-discuss mailing list