Last active
December 14, 2015 15:39
-
-
Save evantahler/5109928 to your computer and use it in GitHub Desktop.
Portable exports function for JS in the browser and in node
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
// myObject.js | |
(function(exports){ | |
var myObject = { | |
thing: 'stuff' | |
}; | |
exports.myObject = myObject; | |
})(typeof exports === 'undefined' ? window : 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
// in the browser: | |
<script src="/path/to/_myObject.js"></script> | |
console.log(myObject.thing); // should say 'stuff' |
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
// in node: | |
var myObject = require('/path/to/_myObject.js').myObject; | |
console.log(myObject.thing); // should say 'stuff' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment