问题描述
console.log(a());
function a(){
console.log("hello");
}
从上面的代码中,我希望"hello"
(和某些undefined
)要登录到控制台.但是萤火虫给了
From above code, i will expect "hello"
(and some undefined
s) to be logged on console. But firebug gives
ReferenceError: a is not defined
那么萤火虫不会吊起吗?
So firebug does not do hoisting?
推荐答案
问题的原因是
由 MDN (涵盖了很多内容)这不是标准的ECMAScript).
by MDN (Much covered here is not standard ECMAScript).
比较以下片段:
alert(c());
function c(){return 42;}
和
{
alert(c());
function c(){return 42;}
}
第一个警报将发出42,而第二个警报将引发ReferenceError
.
The first one will alert 42, whereas the second one will throw ReferenceError
.
以下是在使用Firebug时执行的代码:
And here is the code that gets executed when you are playing with Firebug:
data;
with(_FirebugCommandLine){ // >> block begins
console.log(a());
function a(){
console.log("hello");
}
} // << block ends
更新
观察到的行为似乎在Firefox JavaScript引擎中是一个小故障,因为在chrome和IE9中未观察到此行为,请参见此 fiddle a>.
Update
The behavior observed seems to be a glitch in Firefox javascript engine because it is not observed in chrome and IE9, see this fiddle.
这篇关于萤火虫控制台不做吊装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!