Globalization API discussion
Brendan Eich
brendan at mozilla.com
Sun Nov 20 10:03:45 PST 2011
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.
/be
>
> Rick
>
> On Nov 20, 2011, at 1:40 AM, David Herman <dherman at mozilla.com> wrote:
>
>> On Nov 19, 2011, at 5:50 PM, Brendan Eich wrote:
>>
>>> On Nov 19, 2011, at 2:20 PM, Rick Waldron wrote:
>>>
>>>> Q. We don't use option parameter like that in JS (see previous point for actual example)
>>>>
>>>> Using an object-as-option parameter is a very common API design pattern in real-world JavaScript today - why anyone would say otherwise is confounding.
>>>
>>> Right. For example, ES5's property descriptor and property descriptor map parameters.
>>
>> It was me. I didn't say JS doesn't use options objects. I said the G11n library was using them wrong. They were doing:
>>
>> if (!ops) {
>> ops = { foo: defFoo, bar: defBar, baz: defBaz };
>> }
>>
>> instead of e.g.:
>>
>> if (!ops)
>> ops = {};
>> if (typeof ops.foo === "undefined")
>> ops.foo = defFoo;
>> if (typeof ops.bar === "undefined")
>> ops.bar = defBar;
>> if (typeof ops.baz === "undefined")
>> ops.baz = defBaz;
>>
>> IOW, it shouldn't be all or nothing, but rather each property of the options object is separately optional.
>>
>> Dave
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111120/d38474fa/attachment.html>
More information about the es-discuss
mailing list