在 Safari 中运行以下脚本时(打开检查器)
window.onload = function() {
"use strict";
var x = 1;
debugger; // debugger will auto-break on this line
}
在该断点上时在控制台中请求 x
时出现以下错误:
Error
message: "'with' statements are not valid in strict mode"
删除 "use strict";
行让我可以在该断点处从控制台访问 x
。
两次 x
都显示在边栏的 Scope Variables
下。
最佳答案
这似乎是 Safari 的一个已知问题:https://bugs.webkit.org/show_bug.cgi?id=65829
要重现错误,您只需在停止在断点处并处于严格模式下时在控制台中键入任何代码即可。
这是错误报告中的代码:
(function(){
"use strict";
debugger;
})();
因此,当您处于断点处时,转到控制台并键入 2+3
(或任何表达式),您将收到错误。
关于javascript - 使用严格模式时无法检查范围变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8545191/