Last active
October 20, 2015 14:03
-
-
Save JeremiePat/ae919d09902fffb207de to your computer and use it in GitHub Desktop.
Universal Module boilerplate
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 (name, factory) { | |
'use strict'; | |
// NodeJS | |
if (module && module.exports) { | |
module.id = name; | |
module.exports = factory(); | |
} | |
// CommonJS 1.1 | |
else if (module && exports) { | |
module.id = name; | |
exports = factory(); | |
} | |
// AMD modules | |
else if (typeof define === 'function') { | |
define(name, factory); | |
} | |
// Simple global binding for web browsers | |
else if (window) { | |
// Use `require` to handle dependencies regardless of the environnement | |
window.require = window.require || function (module) { return window[module]; }; | |
window[name] = factory(); | |
} | |
}('myModule', function () { | |
// The code of the module here... | |
return { | |
// Return the module public API | |
}; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment