undefined being treated as a missing optional argument

Brendan Eich brendan at mozilla.org
Sat Apr 14 12:22:07 PDT 2012


There are two cases, both seen in the wild in JS:

1. Delegation of non-keyword parameters:

function add(x = 0, y = 0) {
   return x + y;
}
function inc(opt_y) {
   return add(1, opt_y);
}
assertEq(1, inc());

2. Delegation of keyword parameters:

function add({x = 0, y = 0}) {
   return x + y;
}
function inc({opt_y}) {
   return add({x:1, y:opt_y});
}
assertEq(1, inc({}));

In either case, combinatorial explosing is a problem without a sentinel 
that is passed for missing-actual/not-found-property and that triggers 
defaulting.

Tab and Sam testify about 2 but it's a transformation of 1.

The not-found-property aspect makes the case for undefined as the 
sentinel, IMHO. Not a new masquerades-as-undefined magic value.

/be


More information about the es-discuss mailing list