Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created March 13, 2010 17:27
Show Gist options
  • Save Gozala/331447 to your computer and use it in GitHub Desktop.
Save Gozala/331447 to your computer and use it in GitHub Desktop.
function Global(){}
var G = Global.prototype = window || globalScope;
var global = new Global();
function require(id) {
var preGlobals = Object.keys(global);
var exports = modules[id];
factories[id].call(G, exports, require, metadata[id], global);
var Globals = Object.keys(global).forEach(function(key) {
if (0 > preGlobals.indexOf(key)) { // global introduced by module
if (!global.hasOwnProperty(key)) {
// was not introduced by commonjs module
// cause in that case it would've be global.foo = "bar";
exports[key] = G[key]; // exporting
G[key] = undefined; // removing from global
}
}
})
return exports;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment