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) {
    console.log(x);
    if (truthy()) {
      with ({x: 'ha ha'}) {
        var x = 'ho ho';
        console.log(x);
      }
    }
    function x(){}
        console.log(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?

/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to