Globalization API discussion
Brendan Eich
brendan at mozilla.com
Sun Nov 20 11:24:55 PST 2011
On Nov 20, 2011, at 11:16 AM, Allen Wirfs-Brock wrote:
> On Nov 20, 2011, at 10:03 AM, Brendan Eich wrote:
>
>> On Nov 20, 2011, at 8:12 AM, Rick Waldron wrote:
>>
>>> Ah, yes and agreed. That was definitely not relayed in the message below- thanks for the clarification, the context does make a difference.
>>
>> Destructuring parameters + default values really shine here:
>>
>> function frob(arg1, arg2, {foo = defFoo, bar = defBar, baz = defBaz}) {
>> // just use foo, bar, and baz instead of ops.foo, etc.
>> }
>>
>> instead of the song and dance cited below.
>
> Actually, I think you would want to say:
>
> function frob(arg1, arg2, {foo = defFoo, bar = defBar, baz = defBaz}={}) {
Thanks.
> ...
> }
>
> at least, according to how the ES6 draft is currently written. Destructurings starts by applying ToObject to the value that is to be destructured. ToObject throws for undefined and null. So, destructuring a missing argument would throw.
>
> It may be that for destructuring, in general, we want to treat a null/undefined RHS as { }. Eg:
>
> let {a=1,b=2,c=3} = undefined;
> //should this throw or should this be the same as:
> let {a=1,b=2,c=3} = { };
I would not add more implicit magic to JS. E4X had junk like this in it, which only ever concealed bugs.
/be
>
> whichever way we go, we should treat all destructuring binding forms, including formal parameters, consistently.
>
> Finally, whether or not you want to directly destructure an options object in this matter probably depends upon its treatment of missing options. If a missing option means something different from use the default value (such is the case of property descriptors) then you wouldn't want to unconditionally set missing property values to the default.
>
> Allen
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111120/72465957/attachment.html>
More information about the es-discuss
mailing list