Skip to content

Instantly share code, notes, and snippets.

@dahnielson
Last active May 26, 2018 20:43
Show Gist options
  • Save dahnielson/53a8537f45d67374c094970b1aaf2203 to your computer and use it in GitHub Desktop.
Save dahnielson/53a8537f45d67374c094970b1aaf2203 to your computer and use it in GitHub Desktop.
Module that works directly in browser and node.js
// 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