相关疑难解决方法(0)

为什么我可以在JavaScript中定义之前使用函数?

即使在不同的浏览器中,此代码也始终有效:

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();
Run Code Online (Sandbox Code Playgroud)

但是,我无法找到它应该起作用的单一参考.我第一次在John Resig的演示文稿中看到过这个,但它只是提到了.那里或其他任何地方都没有解释.

有人可以赐教吗?

javascript function

154
推荐指数
4
解决办法
5万
查看次数

标签 统计

function ×1

javascript ×1