fail-fast object destructuring

Brendan Eich brendan at
Wed Jul 11 11:43:18 PDT 2012

Russell Leggett wrote:
> On Wed, Jul 11, 2012 at 1:06 PM, Brendan Eich <brendan at 
> <mailto:brendan at>> wrote:
>     Russell Leggett wrote:
>             Russell asked about 'length' -- per a previous thread, I
>         thought
>             we agreed that one [[Get]] of 'length' would be done before
>             matching if and only if the array literal contains a spread
>             (covering rest, the dual for a pattern of spread in the array
>             literal corresponding to the pattern).
>         Yes, I saw this in the proposal algorithm. The reason I ask is
>         because it seems odd to have an additional structural
>         requirement in some cases but not others. Of course, I
>         understand why, but it sort of makes it look like [] implies
>         additional array-like structure in one case, but not in another.
>     You get what you ask for. Pay as you go. Buy by the yard.
>     Ok, out of clichés but I hope we aren't going to revisit and
>     impose a mandatory [[Get]] of 'length' on all array destructuring
>     forms. That is otiose and costly (potentially very).
>     The presence of is static syntax, so there's no runtime
>     maybe/maybe-not hazard.
> It would not have to be a [[Get]] of 'length', just a check for its 
> existence.

That can still run arbitrary code for a proxy.

> Its no deal breaker for me, but it seemed a little inconsistent.

Remember the Sesame Street song, "one of these things is not like the 
other"? ;-)

  [a, b, c]
  [a, b, ...c]

Special forms are special so semantics can vary according to the syntax.

> We could also be more strict with an Array.isArray check, but that 
> seems too strict. Anyway, just a thought.

Absolutely Array.isArray is too strict, or just wrong. Array patterns 
are for array-likes, not only for arrays.


More information about the es-discuss mailing list