Javascript:被泄露到全球范围内的变量(Firefox插件) [英] Javascript: Variables being leaked into the global scope (Firefox addon)

查看:146
本文介绍了Javascript:被泄露到全球范围内的变量(Firefox插件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 还有一些变量被泄露到全球范围,
可能是因为你使用他们未申报像...



<他没有提及所有的问题变量,有无论如何知道哪些是在全球范围/泄漏?

我有一个多变量的变量,它会花费时间通过其中每一个,以确保他们正确地声明一个变种。



请帮助!



谢谢!

解决方案

如果您正在追踪可能已经由于省略了 var 而被隐式声明为全局的,你可以在 strict模式下运行代码。这会给你一个 ReferenceError ,如果你尝试使用未声明的属性的变量。

 (function(){

use strict; //< - 以严格模式运行此函数中的代码

//你的代码...

test ='tester'; //给出一个ReferenceError

})();

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


I submitted my addon to the AMO direcotry and the editor came back with this:

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

He did not mention all the problem variables, is there anyway to know which are in global scope / getting leaked?

I have a crapload of variables and it would take ages going through each one of them to make sure they were declared properly with a "var".

Please help!

Thanks!

解决方案

If you're trying to track down variables that may have been implicitly declared as global because of the omission of var, you could run the code in strict mode. This will give you a ReferenceError if you try to use variables that haven't been property declared.

(function() {

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

    // your code...

    test = 'tester';  // gives a ReferenceError

})();

You'll need to run it in a supported browser, like Firefox 4 or higher. The "use strict"; declarative will ensure that any code inside the function will be evaluated using the rules of strict mode.

这篇关于Javascript:被泄露到全球范围内的变量(Firefox插件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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