Firefox browser error 22.0?

I'm going crazy - can js redirect a link within scope?

If I am right, is this a serious bug in Firefox 22.0?

if (true) { test(); function test() { alert("success"); } } 

The above code does not work with test () undefined. If the code is executed outside the if statement (or if only the function definition has been moved outside the if ??? statement), then everything will be fine. The same error occurs (not defined) inside other areas, for example, do .. while, etc.

The code above works fine in both IE and Chrome, etc.

* update *

I'm not sure if it is stupid or unreasonable to expect it to be able to do this (of course, it makes sense semantically in the sudo code), but the gods js decided that only statements can appear in such blocks (as mentioned in the link that refers to spidermonkey / ECMA stuff from basilikum) - so no - especially with inconsistent browser processing (if not in strict mode). Thanks to everyone.

+4
source share
1 answer

Firefox does not have its own extensions for ECMAScript.

In ECMAScript, it is not valid to have a function declaration inside a block statement (although most browsers allow it to be in non-strict mode), but in Firefox they have a syntax called a function statement, which allows this. The difference is that a function operator is not evaluated on a separate pass, like a function declaration, so it looks like a function expression in which you cannot use it before defining it.

+5
source

Source: https://habr.com/ru/post/1495517/


All Articles