Skip to content

Instantly share code, notes, and snippets.

@garrypolley
Last active August 29, 2015 14:28
Show Gist options
  • Save garrypolley/f0ac1337cde1cd6dccd4 to your computer and use it in GitHub Desktop.
Save garrypolley/f0ac1337cde1cd6dccd4 to your computer and use it in GitHub Desktop.
default way to make a JavaScript module
(function (global) {
var MODULE_NAME = 'some_name',
moduleObject = {};
/* MODULE CODE GOES HERE
Don't forget to set the attributes of the module on the
`moduleObject`
*/
if (typeof define === 'function' && define.amd) {
// AMD
global[MODULE_NAME] = moduleObject;
define(MODULE_NAME, [], function() {
return moduleObject;
});
} else if (typeof module === 'object') {
// browserify
module.exports = moduleObject;
} else if (typeof exports === 'object') {
// CommonJS
exports = moduleObject;
} else {
// Everything else
global[MODULE_NAME] = moduleObject;
}
}(typeof window !== 'undefined' ? window : this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment