repeated parameter names and default values

Allen Wirfs-Brock allen at
Thu Sep 27 10:12:25 PDT 2012


The notes from last week's meeting said WRT function parameter bindings:

- `var` bindings and are in scope within the function
- cannot use `let` to shadow a parameter
- defaults can refer to any top level binding

Using the above guidance, consider this one:

function test1(b=g) [
    function g() {};
    return typeof g +" "+ typeof b;

presumably, this produces: "function function"
Which means that g is instantiated and initialized prior to apply the defaults to the parameters.

Now consider:

function test2(g,b=g) [
    function g() {};
    return typeof g +" "+ typeof b;

By the same logic, this presumably must also produce: "function function"

So how about:


Is it: "function number" or "function function" or "number number"

In ES5, 

function test3(g) [
    function g() {};
    return typeof g;

produces "function", so the "number number" alternative doesn't seem plausible.  In EX5, nested function declarations over-write parameters that share the same name. 

"function number" may seem reasonable for  the second call of test2 but that seems inconsistent with the first call and with test1.

So, it seems that nested function declarations must be instantiated and bound before parameter instantiation/default value initialization and that parameters that share a name with a such function declaration do not get reinitialized (with either an argument or default value) during parameter instantiation.


More information about the es-discuss mailing list