repeated parameter names and default values

John Lenz concavelenz at gmail.com
Fri Sep 28 07:58:04 PDT 2012


On Thu, Sep 27, 2012 at 10:12 AM, Allen Wirfs-Brock
<allen at wirfs-brock.com>wrote:

> Another:
>
> The notes from last week's meeting said WRT function parameter bindings:
>
> Conclusion/Resolution
> - `var` bindings and are in scope within the function
> - cannot use `let` to shadow a parameter
>

In any scope, or just the top scope of the function?  Restricting "let" in
this fashion seems odd. Does let otherwise have any shadowing restrictions?
 Not that I expect this to be problematic except when translating code from
other languages (either by hand or by a cross compiler).


> - 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;
> }
> console.log(test1());
>
> 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;
> }
> console.log(test2());
>
> By the same logic, this presumably must also produce: "function function"
>
> So how about:
>
> console.log(test2(1));
>
> Is it: "function number" or "function function" or "number number"
>
> In ES5,
>
> function test3(g) [
>     function g() {};
>     return typeof g;
> }
> console.log(test3(1));
>
> 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.
>
> Allen
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120928/37935cf5/attachment-0001.html>


More information about the es-discuss mailing list