Block scoping and redeclarations

Brendan Eich brendan at
Wed Aug 24 18:43:28 PDT 2011

On Aug 24, 2011, at 10:28 AM, Brendan Eich wrote:

> On Aug 24, 2011, at 9:43 AM, Allen Wirfs-Brock wrote:
>> This is essentially the same as the hosting a var out of a catch clause where the var and catch parameter have the same name.
>> I tried to get that defined as an error for ES5 and it didn't fly because of backwards compat. concerns. I suspect we would come to the same conclusion this time.
> Wasn't the concern theoretical?

Allen reminded me that the case he wanted to change for ES3.1 was

  with (obj)
    var prop = 42;

which insanely binds prop in the enclosing function or global object, but then may or may not set obj.prop and leave the prop variable undefined. Nuts, but hoisting is consistent, and I (among others on TC39) did not think ES3.1 should make a breaking change here. Not just because this might be in web content (it's more likely that ... catch (e) { var e... }), but because we weren't supposed to be making breaking changes in ES3.1.

Anyway, Harmony is opt-in, and based on ES5 strict so 'with' is *gone*, so only the catch (e) { var e... } conflict remains to make an error. Again I believe we can get away with this change. It will be an early error, and the pattern (unlike free-floating and repeated var usage in big functions) is exceedingly rare -- never seen by me in the wild.


More information about the es-discuss mailing list