Am I going crazy - js can forward reference within scope right?
If I am right, is this a serious scope bug in Firefox 22.0?
if (true) {
test();
function test() {
alert("success");
}
}
The above code fails with test() being undefined. If the code is executed outside of the if statement (or if just the function definition is moved outside the if statement??!?) then everything is ok. The same error occurs (not defined) inside other scopes like do .. while etc.
The above code works fine as is in IE and Chrome etc!
* update *
Not sure it's daft or unreasonable to expect to be able to do this (certainly makes sense semantically in sudo code) - but the js gods decided only statements can appear in such blocks (as mentioned in the link referencing spidermonkey / ECMA stuff from basilikum) - so no it is - especially with inconsistent browser handling (if not in strict mode). Thanks all.