firebug控制台没有吊装

Riz*_*rif 3 javascript firebug hoisting

console.log(a());
function a(){
    console.log("hello");
}
Run Code Online (Sandbox Code Playgroud)

从上面的代码,我希望"hello"(和一些undefineds)在控制台上登录.但是萤火虫给了

ReferenceError: a is not defined
Run Code Online (Sandbox Code Playgroud)

萤火虫不起吊?

Li0*_*liQ 7

问题的原因是

在子块内声明时,函数不会提升.

通过MDN(这里涉及的很多不是标准的ECMAScript).

比较以下代码段:

alert(c());
function c(){return 42;}
Run Code Online (Sandbox Code Playgroud)

{
    alert(c());
    function c(){return 42;}
}
Run Code Online (Sandbox Code Playgroud)

第一个将提醒42,而第二个将提示ReferenceError.

以下是使用Firebug时执行的代码: Firebug的工具提示

data;
with(_FirebugCommandLine){ // >> block begins
    console.log(a());
    function a(){
        console.log("hello");
    }
} // << block ends
Run Code Online (Sandbox Code Playgroud)

更新
观察到的行为似乎是Firefox javascript引擎中的一个小故障,因为在chrome和IE9中没有观察到它,看到这个小提琴.