Created
February 12, 2014 06:04
-
-
Save r3b/8950747 to your computer and use it in GitHub Desktop.
A nice, simple module container for the browser or Node.
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
| //noinspection ThisExpressionReferencesGlobalObjectJS | |
| (function (global) { | |
| var name = 'MyModule', | |
| short = '_m', | |
| _name = global[name], | |
| _short = (short !== undefined) ? global[short] : undefined; | |
| function Module() { | |
| /* put code in here */ | |
| } | |
| global[name] = Module; | |
| if (short !== undefined) { | |
| global[short] = Module; | |
| } | |
| global[name].noConflict = function () { | |
| if (_name) { | |
| global[name] = _name; | |
| } | |
| if (short !== undefined) { | |
| global[short] = _short; | |
| } | |
| return Module; | |
| }; | |
| if( typeof module !== "undefined" && ('exports' in module)){ | |
| module.exports = global[name] | |
| } | |
| return global[name]; | |
| }(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment