The proposal we accepted, written by Andreas at http://wiki.ecmascript.org/doku.php?id=harmony:refutable_matching, seems clear. Patterns are refutable without an extra ? annotation. Andreas is using prefix-?, note well.

/be

Axel Rauschmayer wrote:
Are patterns in parameter declarations irrefutable? In other words, given:

    function foo({ opt1 }) { return opt1 }

What happens if we call foo()?
    1. An exception is thrown
    2. undefined is returned
I’d expect (2). If opt1 had a default value, I’d expect that value to be returned.

What happens if we call foo({})?
    1. An exception is thrown
    2. undefined is returned

I’m asking, because I’ve seen the pattern

    function foo({ opt1 = 3 } = {}) { return opt1 }

If explicitly marking something as irrefutable is necessary, I’d prefer:

    function foo({ opt1 = 3 }?) { return opt1 }


It’s a bit of a shame that destructuring and parameter declarations diverge, but I guess it can’t be helped.

Axel

--
Dr. Axel Rauschmayer
a...@rauschma.de <mailto:a...@rauschma.de>

home: rauschma.de <http://rauschma.de>
twitter: twitter.com/rauschma <http://twitter.com/rauschma>
blog: 2ality.com <http://2ality.com>

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to