On Tue, May 5, 2009 at 1:37 PM, Peter Michaux <[email protected]> wrote:
> I think optional parameters are the nuisance use case that is fueling
> any discussion about a ||= or ??= operator.
There are other uses that are similar, but wouldn't be covered by
default args. Here's one simple example:
let (hash = {}) function get(key) hash[key] ??= 123
Similarly, if APIs use a single object to take optional args instead
of using function args:
// args is a hash with optional keys "str" and "val"
function foo(args) {
args.str ??= "bar";
args.val ??= 10;
typeof_check(args, { str: "string", val: "number" })
}
So even if there's a better solution for default args than ||= or ??=,
there's still use for the operators.
Ed
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss