Modules

Some simple code to turn a JavaScript module into non-Mozilla-specific code (e.g., if porting to the browser). The use of eval() will probably not be of concern because it is only being used on the EXPORTED_SYMBOLS array which should not depend on user input.

function importModule (thatObj) {
    thatObj = thatObj || window;

    var EXPORTED_SYMBOLS = [
    // Put the symbols here
    ];

    // Your code here...

    // At the end of your code: (assuming neither 'i' nor 'thatObj' is being exported!)
    for (var i=0; i < EXPORTED_SYMBOLS.length; i++) {thatObj[EXPORTED_SYMBOLS[i]] = eval(EXPORTED_SYMBOLS[i]);}
}

or for one-time-only usage of a module:

(function (thatObj) {
    thatObj = thatObj || window;

    var EXPORTED_SYMBOLS = [
    // Put the symbols here
    ];

    // Your code here...

    // At the end of your code: (assuming neither 'i' nor 'thatObj' is being exported!)
    for (var i=0; i < EXPORTED_SYMBOLS.length; i++) {thatObj[EXPORTED_SYMBOLS[i]] = eval(EXPORTED_SYMBOLS[i]);}
})(); // Can put an object argument here