为什么 Chrome 的控制台不再显示功能代码?

Why doesn't Chrome's console display the function code anymore?

以前,如果我有一个函数test,内容是

function test () {
    return true;
}

然后我在控制台中输入 test,然后我会返回:

function () {
    return true;
}

然而现在,它只是 returns function test() 而没有实际的功能代码。我如何将它改回原来的样子(或至少获得功能代码)?

此功能已被 links 替换到定义函数的代码部分。如果你遵循 link,你仍然可以得到方法定义,只是有更多的上下文。如果您想查看完整的方法定义,请尝试对其调用 toString,或者通过加法将其强制转换为字符串。

function test() { return true; }
test.toString(); //=> "function test() { return true; }"
test + ''; //=> "function test() { return true; }"

Chrome DevTools 是开源的并且有 an issues page where you can submit feature requests。如果您想要打开旧行为的选项,post 那里有一个问题。

此后已修改新行为。

现在显示了函数的前几行。所以简短的功能将像以前一样显示。但是,较长的函数会被截断,link 返回到上下文源。