gpt4 book ai didi

Javascript:变量被泄露到全局范围(Firefox 插件)

转载 作者:行者123 更新时间:2023-11-30 09:04:08 25 4
gpt4 key购买 nike

我将我的插件提交到 AMO 目录,编辑返回了这个:

There are still a number of variables being leaked to the global scope, 
probably because you're using them undeclared like...

他没有提到所有问题变量,无论如何要知道哪些在全局范围内/被泄露?

我有一大堆变量,要花很长时间检查每个变量以确保使用“var”正确声明了它们。

请帮忙!

谢谢!

最佳答案

如果您试图追踪可能由于遗漏 var 而被隐式声明为全局的变量,您可以在 严格模式 下运行代码。如果您尝试使用尚未声明属性的变量,这将给您一个ReferenceError

(function() {

"use strict"; // <-- this runs code inside this function in strict mode

// your code...

test = 'tester'; // gives a ReferenceError

})();

您需要在受支持的浏览器中运行它,例如 Firefox 4 或更高版本。 "use strict"; 声明将确保函数内的任何代码都将使用严格模式的规则进行评估。

关于Javascript:变量被泄露到全局范围(Firefox 插件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6616267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com