Skip to content

Instantly share code, notes, and snippets.

@james-huston
Created September 15, 2014 17:25
Show Gist options
  • Save james-huston/607ea10a911069c89045 to your computer and use it in GitHub Desktop.
Save james-huston/607ea10a911069c89045 to your computer and use it in GitHub Desktop.
Easy to read amd/commonjs/window export
var MyModule = {};
// AMD support
if (typeof define === 'function' && define.amd) {
define(function () { return MyModule});
// CommonJS and Node.js module support.
} else if (typeof exports !== 'undefined') {
// Support Node.js specific `module.exports` (which can be a function)
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = MyModule;
}
// But always support CommonJS module 1.1.1 spec (`exports` cannot be a function)
exports.MyModule = MyModule;
} else {
window.MyModule = MyModule;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment