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}={}) { ... } 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} = { }; 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
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss