fail-fast object destructuring

Andreas Rossberg rossberg at google.com
Wed Jul 11 08:31:36 PDT 2012


On 11 July 2012 17:20, Russell Leggett <russell.leggett at gmail.com> wrote:

> On Wed, Jul 11, 2012 at 7:14 AM, Andreas Rossberg <rossberg at google.com>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.

/Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120711/e78ee51e/attachment.html>


More information about the es-discuss mailing list