Last active
May 5, 2021 01:06
-
-
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.
This file contains hidden or 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(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