# ModuleJS **Repository Path**: mirrors_TooTallNate/ModuleJS ## Basic Information - **Project Name**: ModuleJS - **Description**: Asynchronous CommonJS-like Module Loader for web-browsers. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-18 - **Last Updated**: 2026-06-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ModuleJS ======== ### Asynchronous [CommonJS][] Module Loader for web-browsers. This script allows the use of "modules" within your JavaScript (usually web application). It uses [SandboxJS][] underneath the hood in order to execute modules within their own, isolated, JavaScript scope. This means that executed modules do NOT have access to the global `window` or `document` objects, unless the page author explicitly allows it. Writing a Module ---------------- A "module" is simply a JavaScript file that exports objects (i.e. functionality) for other modules to use. A top-level module doesn't depend on any other modules, and simply assigns properties to the global `exports` object for others to use: // foo.js exports.upper = function(str) { return str.toUpperCase(); } Any other module that depends on other modules MUST use the `module.load()` function to explicity specify which modules it depends on. The `exports` of the required modules are passed in as arguments: // bar.js module.load('./foo', function(foo) { console.log(foo.upper("test")); // "TEST" }); In the case of `bar.js`, the callback ("factory") function won't be executed until after the dependency list has been satisfied. The "main" module ----------------- Accessible as `module.main`; the "main" module is everything that your export in the global scope. Since by default your module has no access to anything except JavaScript primitives, you might want to export some hooks into your web app in the global scope (custom logging, etc.). To load other modules, `module.load`! This may be done in an inline ` [SandboxJS]: https://github.com/TooTallNate/SandboxJS [CommonJS]: http://wiki.commonjs.org/wiki/Modules