Created
December 1, 2014 23:07
-
-
Save frostney/ca41937e0eb86fb4a833 to your computer and use it in GitHub Desktop.
Requiring global properties like CommonJS modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var modules = {}; | |
var require = function(name) { | |
var globals = Object.keys(window); | |
if (Object.keys(modules).length !== globals.length) { | |
globals.forEach(function(item) { | |
if (!Object.hasOwnProperty.call(modules, item)) { | |
modules[item] = window[item]; | |
} | |
}); | |
} | |
return modules[name]; | |
}; | |
window.require = require; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment