pyk*_*yke 6 firefox firefox-developer-tools
如何重置Firefox Web控制台以便能够使用已经声明的变量?
console.clear()只会清除输出。已经声明的所有变量都保留在内存中。我正在努力摆脱:
Error: "SyntaxError: redeclaration of..."
Run Code Online (Sandbox Code Playgroud)
When testing something, use the same construction you would (well, should) use to prevent code and variables being dropped in the global scope. Use Immediately Invoked Function Expressions (IIFE) and place your code in it. Each IIFE is it's own context, so re-declaring is not a problem.
(function () {
const myConstant = 1;
console.log(myConstant);
}());
Run Code Online (Sandbox Code Playgroud)
Note that Chrome 80 allows redeclaration of const and let. There exists a relevant bug in bugzilla for Firefox.
| 归档时间: |
|
| 查看次数: |
923 次 |
| 最近记录: |