Skip to content

Instantly share code, notes, and snippets.

@nash403
Last active September 18, 2016 18:01
Show Gist options
  • Save nash403/eeab316f7377aa4e36b1a0966a525841 to your computer and use it in GitHub Desktop.
Save nash403/eeab316f7377aa4e36b1a0966a525841 to your computer and use it in GitHub Desktop.
Writing JS for both Node & Browser
<script src="mymodule.js"></script>
<script>
alert(mymodule.test());
</script>
(function(){
// your code goes here
function notExported(){
return "shh, I'm not here";
}
function test(){
return 'hello world';
};
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = test; // default
// module.exports.otherExport = otherExport;
}
else {
window.test = test;
// module.exports.otherExport = otherExport;
}
})();
var mymodule = require('./mymodule'),
sys = require('sys');
sys.puts(mymodule.test());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment