On Mon, May 14, 2012 at 11:57 AM, Claus Reinke <claus.rei...@talk21.com> wrote:
> What should be the output of the following code?
>
> (function(){
>
> try {
>  throw "hi";
> } catch (e) {
>  var e = "ho";
>  var o = "hu";
>  var u;
>  console.log(e);
> }
> console.log(e,u,o);
>
> }());
>
> It seems clear that the first console.log should output 'ho'.
> Implementations seem to disagree on the second console.log, though.
>
> From my current understanding of the spec, I expected:
>   undefined undefined 'hu'
>

Inside the catch, the catch-scope is first for reading and writing.
But the catch scopes are ignored for declaring new variables. So your
expectation seems to be the correct one. `e` is created in the scope
of the anonymous function. Likewise, `o` and `u` are created in that
scope too (so neither throw at the second console.log). "ho" is
assigned to the catch-scope `e`, since that's the first scope in the
scope traversal lookup at that point. Catch scopes are weird, yo.

- peter
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to