0

Firefox addon example:

    var MyAddonNamespace = {
        local_variable: null,
        local_method: function() {
            return 'string';
        }
    };

window.addEventListener("load", function(e) {
    MyAddonNamespace.local_method();
}, false);

Warning: Your add-on contains a large number of global variables, which can conflict with other add-ons. For more information, see http://blog.mozilla.com/addons/2009/01/16/firefox-extensions-global-namespace-pollution/, or use JavaScript modules.

How I can fix it? Thanks in advance.

nmaier
  • 32,336
  • 5
  • 63
  • 78
owl
  • 4,201
  • 3
  • 22
  • 28
  • Might be a false-positive, or might be some other script you include... Cannot say given the limited information – nmaier Jul 08 '14 at 14:57

1 Answers1

0

You can hide variables from the global scope by putting them into an anonymous function (explanation of anymous functions).

In your case that would look as follows:

(function(){
    var MyAddonNamespace = {
       local_variable: null,
       local_method: function() {
          return 'string';
       }
   };
   window.addEventListener("load", function(e) {
      MyAddonNamespace.local_method();
   }, false);
})();
Community
  • 1
  • 1
Atabascael
  • 26
  • 3
  • Thanks. But I tried it and have a error: MyAddonNamespace is not defined. How I can use MyAddonNamespace methods in xul? – owl Jun 14 '14 at 11:44
  • Unfortunately, I have never worked with XUL. Is there any other place outside the anonymous function where you try to access MyAddonNamespace? – Atabascael Jun 14 '14 at 11:52