Skip to content

Instantly share code, notes, and snippets.

@binarymax
Last active May 5, 2021 01:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binarymax/b431108f6c0f67c613b3986eb6d44732 to your computer and use it in GitHub Desktop.
Save binarymax/b431108f6c0f67c613b3986eb6d44732 to your computer and use it in GitHub Desktop.
The most basic module.exports hackery polyfill for browser. Adds lots of stuff to the global scope.
;(function(global){
global.module = {};
global.require = function(){};
Object.defineProperty(global.module,'exports',{
set:function(m) {
if (typeof m === 'function') {
var str = m.toString();
var name = str.substring(9,str.indexOf('(')).replace(/\s+/,'');
global[name] = m;
} else if (typeof m === 'object') {
for (var p in m) {
if (m.hasOwnProperty(p)){
global[p] = m[p];
}
}
}
}
});
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment