Thanks, didn’t know that applied to parameters, too. Then the following two
functions are equivalent(?)
function (arg0, arg1, arg2) {
// ...
}
function (...args) {
let [arg0', arg1', arg2'] = args;
// ...
}
With the following rules for translating argi -> argi':
- paramName -> ?paramName
- pattern -> pattern (rest parameters, parameter default values, curly braces,
square brackets)
On Mar 20, 2013, at 22:45 , Brendan Eich <[email protected]> wrote:
> 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.
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss