fail-fast object destructuring

Brendan Eich brendan at
Wed Jul 11 09:09:11 PDT 2012

Andreas Rossberg wrote:
> On 11 July 2012 17:20, Russell Leggett <russell.leggett at 
> <mailto:russell.leggett at>> wrote:
>     On Wed, Jul 11, 2012 at 7:14 AM, Andreas Rossberg
>     <rossberg at <mailto:rossberg at>> wrote:
>         AFAICS, '?' on a variable itself would always be redundant,
>         because a variable pattern is irrefutable anyway.
>     So you're saying that even this should match in a refutable pattern:
>        let [a,b,c] = [1,2];
>     I would expect that to fail, especially in a hypothetical pattern
>     matching construct.
> That would fail because the array pattern is refutable. What I meant 
> is something else, namely that there is no difference between these:
>   let x = ...
>   let ?x = ...
> or these:
>   let {x: x, y: y} = ...
>   let {x: ?x, y: ?y} = ...
> Pattern matching recursively decomposes the RHS and matches a 
> (sub)value against the respective (sub)pattern of the LHS. Once you 
> reach a variable, that submatch is unconditional, so a '?' doesn't 
> change anything.

Thanks -- this recovers my forgotten reason for advocating prefix-? on 
property names, not binding identifiers (which occupy the value 
positions in object literals). I think it addresses Allen's objection 
about why ? is not available for all bindings, simple identifiers too. 
It is part of the pattern grammar for property names only.

For arrays, the just-so story of prefix-? having an implicit "0", "1", 
etc. name after it works well enough -- there's no difficulty computing 
indexes statically.

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


More information about the es-discuss mailing list