return when desugaring to closures

Waldemar Horwat waldemar at
Mon Oct 13 15:51:02 PDT 2008

Brendan Eich wrote:
> After some experiments, we decided for ES4 to make let and var the  
> same at top level in a function or global code.
> This helped avoid implementation pain: very long scripts on the web,  
> consisting of many statements in a row, motivate statement-wise  
> parsing and cumulative code generation, which is straightforward in  
> the absence of goto. Yet scope changes (e.g. due to a tardy rogue let  
> x; after thousands of statements the first of which uses x) require a  
> separate pass to generate the necessary block set-up code before the  
> first use of x.
> Unifying let and var at top level also reduces the cognitive load  
> (number of scopes in mind) and eliminates useless name shadowing  
> opportunities.
> But such let/var unification at top level in a function body does  
> leave bad old arguments[0] aliasing x in the above example, allowing  
> mutation of otherwise lexical let x; (change var to let and fill in  
> the ... with arguments[0] = 42; return x). The answer that we chose  
> for ES4, and the one that's already agreeable in committee for  
> Harmony, was "deprecate arguments by providing optional and rest  
> parameters".

You can't do that.

function f() {
  x = 15;
  let t = some_runtime_expression;
  let x:t = ...

What is the type of x at the beginning of the function?


More information about the Es-discuss mailing list