Generator issue: exceptions while initializing arguments

Brendan Eich brendan at
Mon Sep 10 14:42:03 PDT 2012

Kevin Smith wrote:
>     But as I pointed out, we have problems already in JS:
>       function f(x) {var x; ...}
>     the var x restates the formal parameter. It does not shadow it.
> Ah - observable here:
> > function crazypants(x) { var x; return x; }
>     undefined
> > crazypants(123);
>     123
> If it shadowed, we would expect undefined.  Even so, information can 
> only flow from left to right across the curly boundary.

Not true of curlies in general in JS as we know and love it:

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

>  That's expected.  But if we allow parameter default expressions to 
> have visibility into the function body, then we have bidirectional 
> flow across curlies.

In the above function f, which is pure ES3 (assume truthy() returns only 
truthy values and console.log works as expected), the hoisting of 
function x means f logs 'function x(){}' then 'ho ho' then 'function x(){}'.

If you change the with head's object to have property y not x, then f 
logs 'function x(){}', then 'ho ho', then 'ho ho'.

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

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


More information about the es-discuss mailing list