Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
Forked from anonymous/smd.js
Last active September 3, 2017 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gordonbrander/8811045 to your computer and use it in GitHub Desktop.
Save gordonbrander/8811045 to your computer and use it in GitHub Desktop.
(function(exports) {
var modules = {}
var factories = {}
// Require a module by id.
function require(id) {
if (!(id in factories)) throw Error(id + ' module is not defined')
if (!(id in modules)) {
modules[id] = {}
factories[id](require, modules[id])
}
return modules[id]
}
exports.require = require
require.modules = modules
require.factories = factories
// Define a module with id.
function define(id, factory) {
if (id in factories) throw new Error(id + ' module is already defined')
factories[id] = factory
}
exports.define = define
})(this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment