Skip to content

Instantly share code, notes, and snippets.

@cethap
Forked from gordonbrander/smd.js
Created March 21, 2014 15:45
Show Gist options
  • Save cethap/9689127 to your computer and use it in GitHub Desktop.
Save cethap/9689127 to your computer and use it in GitHub Desktop.
Create Module js
var __modules__ = {};
function require(id) {
var module = __modules__[id];
if(!module) throw new Error('Module not yet defined');
// Get the module's exports lazily (allows registration in any order as long
// as main script entry point comes last).
return __modules__[id] = (typeof(module) === 'function') ?
module(require, {}) : module;
}
function define(id, factory) {
if (__modules__[id]) throw new Error('Another module already has this name');
__modules__[id] = factory;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment