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

Rya*_*yan 1 javascript firefox global-variables firefox-addon

我将我的插件提交给AMO目录,编辑回来了:

There are still a number of variables being leaked to the global scope, 
probably because you're using them undeclared like...
Run Code Online (Sandbox Code Playgroud)

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

我有一大堆变量,它们需要花费很长时间才能确保它们用"var"正确声明.

请帮忙!

谢谢!

use*_*716 5

如果您正在尝试跟踪由于省略而可能已隐式声明为全局的变量,则var可以运行代码strict mode.ReferenceError如果您尝试使用未声明属性的变量,这将为您提供.

(function() {

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

    // your code...

    test = 'tester';  // gives a ReferenceError

})();
Run Code Online (Sandbox Code Playgroud)

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