Autobinding destructuring

David Bruant bruant.d at
Sat Aug 4 15:56:55 PDT 2012

Le 04/08/2012 16:19, Brendan Eich a écrit :
> David Bruant wrote:
>>     var context = 
>> document.getElementsByTagName('canvas')[0].getContext('2d');
>>     // bikeshed syntax for binding destructuring, my point isn't 
>> about syntax here
>>     var #{beginPath: begin, moveTo, lineTo, stroke, closePath: end} = 
>> context;
>>     // extracted methods are bound to the context object.
> The # was somewhat wanted for records, tuples, and const functions, once.
Ok. As I try to highlight each time I talk about syntax, I'm usually 
more interested in having a new syntax for something than in the exact 
Syntax and ES grammar really are not my specialty. When I propose 
something I make sure it's a syntax error in current engines, but that's 
as far as I go.
So really, the exact syntax proposal can be thrown away if there are 
better ideas or if it conflicts with something else.

> For DRY, new syntax seems required. From
The idea of combining the bind operator and bound destructuring is a 
good one in my opinion.

> Your wish to mix auto-bound and unbound method destructuring could be 
> met by:
>     var {unbound, ::bound} = object;
> which could be written without destructuring, but with the bind 
> operator strawman, as
>     var unbound = object.unbound, bound = ::object.bound;
+1, if that syntax works, that's fine for me :-)


More information about the es-discuss mailing list