使用严格模式时无法检查范围变量 [英] Can't inspect scope variable when using strict mode

查看:47
本文介绍了使用严格模式时无法检查范围变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Safari 中运行以下脚本时(打开检查器)

When running the following script in Safari (with the Inspector open)

window.onload = function() { 
    "use strict";
    var x = 1;
    debugger; // debugger will auto-break on this line
}

当我在断点处请求 x 时,我收到以下错误:

I get the following error when asking for x in the console while being on that breakpoint:

Error
message: "'with' statements are not valid in strict mode"

删除 "use strict"; 行可以让我在断点处从控制台访问 x.

Removing the "use strict"; line lets me access x from the console while on that breakpoint.

两次 x 都显示在侧边栏中的 Scope Variables 下.

Both times the x is shown under Scope Variables in the sidebar.

推荐答案

这似乎是 Safari 的一个已知问题:https://bugs.webkit.org/show_bug.cgi?id=65829

This appears to be a known issue with Safari: https://bugs.webkit.org/show_bug.cgi?id=65829

要重现错误,您只需在断点处和严格模式下在控制台中键入任何代码即可.

To reproduce the Error, you simply need to type any code into the console while stopped at a breakpoint and while in strict mode.

这是错误报告中的代码:

Here's the code from the bug report:

(function(){
    "use strict";
    debugger;
})();

因此,当您在断点处时,转到控制台并输入 2+3(或任何表达式),您将收到错误信息.

So when you're at the breakpoint, go to the console and type 2+3 (or any expression), and you'll get the Error.

这篇关于使用严格模式时无法检查范围变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆