fail-fast object destructuring

Andreas Rossberg rossberg at google.com
Wed Jul 11 04:16:25 PDT 2012


On 10 July 2012 10:47, Russell Leggett <russell.leggett at gmail.com> wrote:

> Another thing that I was also thinking is that it might look a little
> nicer if the ? was a post-fix instead of a pre-fix.
>
>     let {first, last, company?} = contact;
>
> I might be missing why this wouldn't work out, but it aesthetically just
> looks right to me. It looks like the regex operator, and is also obviously
> the position it would be in english.
>

Even parsing issues aside, I don't like postfix better. It is easier to
miss, especially if ? was possible on patterns, not just properties.
Consider:

  let {the, that: {x, y}, those, theirs: {what, why}, thus}? =
callSomething()

How easy is it to miss the final '?' when looking for the binding of 'x'?

But even on longish property names it can be a tad too easy to overlook:

  let {what, why, whatTheHeckIsGoingOn?} = callSomething()

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


More information about the es-discuss mailing list