Last active
May 26, 2018 20:43
-
-
Save dahnielson/53a8537f45d67374c094970b1aaf2203 to your computer and use it in GitHub Desktop.
Module that works directly in browser and node.js
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
// Check whether we are in browser or node.js | |
var _self = (typeof window !== 'undefined') ? window : {}; | |
// Scoping with anonymous closure for browser | |
var Foo = (function(){ | |
var _ = _self.Foo = { | |
init: function() { | |
} | |
} | |
if (!_self.document) { | |
return _self.Foo; // in node.js | |
} | |
document.addEventListener('DOMContentLoaded', _.init); | |
return _self.Foo; // in browser | |
})(); | |
// Export if we are required as a module | |
if (typeof module !== 'undefined' && module.exports) { | |
module.exports = Coda; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment