【发布时间】:2010-09-20 16:02:43
【问题描述】:
此代码始终有效,即使在不同的浏览器中也是如此:
function fooCheck() {
alert(internalFoo()); // We are using internalFoo() here...
return internalFoo(); // And here, even though it has not been defined...
function internalFoo() { return true; } //...until here!
}
fooCheck();
不过,我找不到一个关于为什么它应该起作用的单一参考。 我首先在 John Resig 的演示文稿中看到了这一点,但它只是被提及。那里或任何地方都没有任何解释。
有人可以告诉我吗?
【问题讨论】:
-
在较新版本的 firefox 中,如果代码在 try/catch 中,这将不起作用。看到这个小提琴:jsfiddle.net/qzzc1evt
标签: javascript function