Nested functions may be defined only at the top level of the function within which they are nested. That
is, they may not be defined within statement blocks, such as the body of an if statement or while
loop.[*] Note that this restriction applies only to functions defined with the function statement . Function
literal expressions, which are described in the next section, may appear anywhere.
[*] Different implementations of JavaScript may be more relaxed about function definitions than the standard requires. For example,
Netscape's implementation of JavaScript 1.5 allows "conditional function definitions" that appear within if statements.
JavaScript嵌套函数限制
本文介绍了JavaScript中嵌套函数的定义限制,指出它们只能位于顶级作用域内而不能出现在if语句或循环体内。此外,文章还对比了不同实现间的差异,并解释了函数表达式可以在任意位置使用。
869

被折叠的 条评论
为什么被折叠?



