Last active
December 18, 2015 02:38
-
-
Save husa/5712005 to your computer and use it in GitHub Desktop.
how to declare a global variable or export it as CJS or AMD module if posible. 'this' must refer to global object or you can put this code into global scope
This file contains 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
// myModule - is our global we want to export | |
var root = this; | |
if (typeof(exports) !== 'undefined') { | |
if (typeof(module) !== 'undefined' && module.exports) { | |
exports = module.exports = myModule; | |
} | |
exports.myModule = myModule; | |
} else { | |
if (typeof define === 'function' && define.amd) { | |
define('myModule', [], function(){ return myModule; }); | |
} | |
root.myModule = myModule; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment