undefined undefined hu

is what should be produced according to the spec.

Divergence among implementations is a good sign that there is an opportunity to clean up this particular mess.

Yes, please!-)

The current ES6 draft requires an early error for this function
because it is trying to hoist a var declaration across a block-level
declaration of the same identifier.  EG,

'let' vs 'var' would have been my next question. Good to
know that this particular issue does not propagate to 'let'!

Because let is a new feature, this restriction doesn't introduce any
backwards compatibility issues. However, for consistency, the draft
also currently applies the same let declaration restrictions to catch
parameters.

Even better!-) And in line with treating catch as an anonymous function.

Claus

Your experiment suggests that that we might actually be able to to that ...

Allen





On May 14, 2012, at 2:57 AM, Claus Reinke 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'

which I consider unfortunate; especially the first 'undefined'
was intended to demonstrate the bad effects of separating declaration from initialization while treating catch and function differently, in terms of scoping.

node, opera: undefined undefined 'hu'

firefox 12 complains: 'e is not defined'

ie 9 outputs: houndefinedhu

It looks as if firefox misses the hoisted declaration of 'e'
(it doesn't complain about 'u', only about 'e') while ie9 somehow merges the declaration and the catch parameter.

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





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

Reply via email to