return when desugaring to closures

Felix felix8a at
Fri Aug 22 15:05:54 PDT 2008

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'?

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.

More information about the Es-discuss mailing list