Refutable destructuring

Axel Rauschmayer axel at rauschma.de
Fri Aug 9 14:54:30 PDT 2013


AFAICT, there is no current consensus on whether destructuring assignment is refutable by default or not:
https://github.com/rwldrn/tc39-notes/blob/master/es6/2013-07/july-23.md#44-consider-deferring-es6-refutable-matching

Could we make destructuring assignment fail soft and introduce a marker for refutable parts of a pattern (e.g. a prefix `!`):

    let { !a: foo, b: bar } = { a: 1 };  // ok: foo = 1, b = undefined
    let { !a: foo, b: bar } = { };  // exception

This would have one advantage: It would be possible to bring this operator to parameter declarations (allowing one to declaratively specify a minimum arity). Then destructuring assignment and parameter handling would work very similarly.

    function bla(!mandatoryArg, optionalArg1, optionalArg2 = 123) {
        ...
    }


Axel

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

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


More information about the es-discuss mailing list