Last active
August 29, 2015 14:28
-
-
Save garrypolley/f0ac1337cde1cd6dccd4 to your computer and use it in GitHub Desktop.
default way to make a JavaScript module
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) { | |
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