destructuring: as patterns?

Brendan Eich brendan at mozilla.org
Wed Apr 18 08:54:04 PDT 2012


Clearly it has utility. Same with callable object protocols ;-).

The debate is always about whether every useful thing must be included, 
when there are long-hands aplenty. This cuts both ways, since 
destructuring is mainly an affordance, syntactic sugar.

The other issue here is standardized grammar and parsing algorithm 
(LR(1) with lookahead and [no LineTerminator here] restrictions). In 
binding forms we can specialize the pattern sub-grammar and IIRC Allen's 
draft ES6 spec does.

In contrast, for general destructuring assignment expressions, the LHS 
must be covered by ObjectLiteral or ArrayLiteral. No 'as' in those, but 
perhaps this just says that 'as', if we add it, is only in the binding 
forms' pattern sub-grammar.

/be

David Nolen wrote:
> On Wed, Apr 18, 2012 at 11:26 AM, Brendan Eich <brendan at mozilla.org 
> <mailto:brendan at mozilla.org>> wrote:
>
>     We've supported destructuring for years and no one has asked for
>     this. I say YAGNI and when in doubt, leave it out. One can always
>     write two destructuring declarations without much repetition:
>
>
> But who has been using it? Certainly not the general JS development 
> community.
>
>      let {b} = obj;
>      let {x,y} = b;
>
>     but of course one would just write
>
>      let {x, y} = obj.b;
>
>     in that contrived case.
>
>     Main thing is, not having as-patterns is not a big deal based on
>     experience with JS1.7+ since 2006 in Mozilla code.
>
>     /be
>
>
> I've found it quite useful in Clojure/Script and I'm sure folks who 
> have encountered the feature in the ML derived languages would agree.
>
> David
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list