Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

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

Document Tags and Contributors

 Contributors to this page: wbamberg, Nickolay, Brettz9
 Last updated by: wbamberg,