Revenge of the double-curly [Was: return when desugaring to closures]

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Fri Oct 10 09:48:48 PDT 2008


P T Withington wrote:
> On 2008-10-10, at 02:29EDT, Brendan Eich wrote:
> 
>> An agreement from TC39 this past sprint was that function definitions
>> directly nested in blocks, not specified by ES3, defined block-local
>> (let) bindings.
> 
> Holy smokes.  Does that mean we are all going to be writing
> 
>    function ... () {{
>      ...
>    }}
> 
> to get 'normal' scoping of function body declarations???

I don't think so, because at the top level of a function, a function-local
declaration and a block-local declaration are the same thing. Have I
missed something?

Will function definitions be in scope throughout the enclosing block, or
only after and within the definition? E.g.

function f() {
  var x = "foo";
  if (true) {
    print(x);        // "function x() { x(); }", "undefined", "foo",
                     //   run-time exception, or static error?

    x();             // call to x(), run-time exception, or static error?

    function x() {
      x();           // presumably allowed
    }
  }
}

I think they should be in scope throughout the block -- for consistency
with the "processed for function declarations" rule in ES3 section 13,
because being able to put function declarations anywhere in a block may
allow a clearer code layout in some cases, and to allow mutually
recursive functions within a block.

-- 
David-Sarah Hopwood



More information about the Es-discuss mailing list