Skip to content

Instantly share code, notes, and snippets.

@frostney
Created December 1, 2014 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frostney/ca41937e0eb86fb4a833 to your computer and use it in GitHub Desktop.
Save frostney/ca41937e0eb86fb4a833 to your computer and use it in GitHub Desktop.
Requiring global properties like CommonJS modules
(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