This behavior has some history. At the beginning (for example, ECMA-262 ed 3, which was the first true version of the specification), function declarations were not allowed inside blocks (see Kangax, Function Operators ).
However, IE simply saw them as function declarations and “lifted” them, while Mozilla browsers (possibly Netscape Navigator) conditionally rated them as a function operator, an allowed specification extension. Some other browsers threw an error, which probably should have done.
, ECMA-262 ed 5 aka ES5, ( , ECMAScript 2015 B.3.3. . -). , , , , , , .
, , ECMAScript ed 5.
. , JavaScript? Q & A Ed 5.
, "" , , , :
var someFn;
if (something) {
someFn = function(...params1) {};
} else {
someFn = function(...params2) {};
}
comp.lang.javascript: FAQ - ? 2010 . "" ,
Kangax:
... - - ( ) ( Function ), ?
:
, ECMA , , . , ( , IE " ", .. , , , ). ECMAScript , (ECMA), . (, , JavaScript (tm) ECMAScript , , JavaScript (TM)).
, .