Generator issue: exceptions while initializing arguments

Kevin Smith khs4473 at
Tue Sep 11 06:56:29 PDT 2012

> function f(x) {
>     console.log(x);
>     if (truthy()) {
>       with ({x: 'ha ha'}) {
>         var x = 'ho ho';
>         console.log(x);
>       }
>     }
>     function x(){}
>         console.log(x);
>   }

> In these cases there is information flowing right to left, even across
> unbalanced left brace!

You're not seriously arguing for how new things should work based on "with"
and "arguments" are you?  : )

This is JS. We can't change it. Are default parameters really the place to
> make a new last stand for something different?

Maybe not.  It may not be worthwhile to try and maintain the "curly law"
here, but just as a thought experiment:

    function g() { return "outer"; }
    function f(a = g()) { return a; function g() { return "inner"; } }

What should we see logged?  If we're inclined to think that curlies should
define scope boundaries, then we might answer "outer".  In order to make
that happen, we'd need to introduce a new scope in between f's declaration
and f's body:

    {0: g, f {1: a } {2: a, g } }

where 0 is the outer scope, 1 is the scope of parameter default
expressions, and 2 is the function body scope.  This model isn't
conceptually clean either though, because we have weird "copy-like"
semantics as parameter values "teleport" from scope 1 to scope 2.  Meh.

If both scoping semantics (Jason's "top of function body" and the one
above) are awkward for different reasons, then maybe there's a better way
to approach default values.

A while ago existential and default operators were discussed, but I didn't
pay much attention.  If we have a default operator, then we could cut
default parameter values altogether:

    function f(a = g()) {
      return a;
      function g() {}

    // is the same as:

    function f(a) {
      return a;
      function g() {}

It's not quite as pretty as parameter defaults, but it doesn't suffer from
the scope awkwardness, either.  As an added bonus the loc1 vs. loc2 issue
that started the thread basically goes away.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list