Last active
December 21, 2015 13:49
-
-
Save lylijincheng/6314976 to your computer and use it in GitHub Desktop.
modules exports.
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
// A|CMD Module | |
// Step A: ()() | |
// Step B: (function() {})(function(){}) | |
// Rock and roll | |
(function(definition) { | |
// RequireJS | |
if (typeof define === 'function') { | |
define(definition); | |
} else { | |
definition(); | |
} | |
})(function() { | |
// Define a module | |
}); |
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
(function() { | |
/* ... Code that defines MyModule ... */ | |
var MyModule = {}; | |
var root; | |
if (typeof self !== 'undefined') { | |
// Web Worker | |
root = self; | |
} else if (typeof window !== 'undefined') { | |
// Browser | |
root = window; | |
} else if (typeof global !== 'undefined') { | |
// NodeJS | |
root = global; | |
} | |
root.MyModule = MyModule; | |
if (typeof module !== 'undefined') { | |
module.exports = MyModule; | |
} | |
})(); | |
// Simplified: | |
(function(root) { | |
/* ... Code that defines MyModule ... */ | |
var MyModule = {}; | |
root.MyModule = (root.module || {}).exports = MyModule; | |
})(this); | |
// my: exports to window | |
new function() { | |
/* ... Code that defines MyModule ... */ | |
var MyModule = {}; | |
this.MyModule = (this.module || {}).exports = MyModule; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment