return when desugaring to closures

Ingvar von Schoultz ingvar-v-s at comhem.se
Fri Aug 22 07:28:44 PDT 2008


Brendan Eich wrote:
> On Aug 21, 2008, at 7:04 PM, Peter Michaux wrote:
>> On Thu, Aug 21, 2008 at 6:34 PM, Brendan Eich <brendan at mozilla.org>  
>> wrote:
>>> The destructuring pattern here is an array, but objects work too:
>>> js> let {length: len} = foo()
>> The above has always instinctively looked to me like the variable
>> "length" is being assigned the value of the "len" property of the
>> object returned by foo. That is the way an object literal works: the
>> right value is assigned to the left property.

I find that it's hard to get used to. I keep interpreting this...

         var {a: x, b: y, c: z} = fn();

...as...

         with (fn())
         {   temporary_object = {a: x, b: y, c: z}
         }
         // Splash out the object.

...(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();

...but with the chosen inverted semantics it would have to be
written like this...

         var {x: a, y+z: b} = fn();

...which looks weird.

> Probably not instinct (no survival advantage ;-); possibly lack of  
> familiarity with the new form in context. Try using it in more  
> realistic code for a few days (especially the shorthand form)

The shorthand form would be the same (or am I missing something?)

> and  
> ping me if it still reads like an object initialiser.

Stockholm syndrome!

People can get used to anything. Just look at Perl. :-)

-- 
Ingvar von Schoultz


More information about the Es-discuss mailing list