Skip to content

Instantly share code, notes, and snippets.

@r3b
Created February 12, 2014 06:04
Show Gist options
  • Select an option

  • Save r3b/8950747 to your computer and use it in GitHub Desktop.

Select an option

Save r3b/8950747 to your computer and use it in GitHub Desktop.
A nice, simple module container for the browser or Node.
//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