Take a look at what is called "Javascript shared code modules" or JSM.
Primary documents are here:
https://developer.mozilla.org/En/Using_JavaScript_code_modules
Each .js file in your addon that needs shared memory will open with the following line:
Components.utils.import("resource://xxxxxxxx/modules/[yourFilenameHere].jsm", com.myFirefoxAddon.shared);
The above line opens [yourFilenameHere] .jsm and loads the functions exported (see below) functions and variables into the com.myFirefoxAddon.shared object. Each instance of the loaded object points to the same instance in memory.
Please note that if you want to have any hope that you will add it after moderation, you will need to write all your code in com.myFirefoxAddon. * Object type, as goons in AMO prevent the approval of addons that do not respect the global namespace
The biggest caveat for JSM is that you need to manually export each function that you want to use for the rest of your code ... since JS does not support public / private types, this leads me as a kind of "public" support for the "poor" "... in any case, you will need to create an array of EXPORTED_SYMBOLS somewhere in your JSM file and name each function or object that you want to export, for example:
var EXPORTED_SYMBOLS = [ "SERVER_DEBUG", "SERVER_RELEASE", "LIST_COUNTRIES", "LIST_TERRITORIES_NOEX", "urlTable", "globals", "iStrSet", "globalStartup", "thinger", "myObject" ]
source share