I'd like to make a Javascript file that
exports its content (e.g. a class) if it canexport(e.g. it has been loaded with<script type="module">)- and otherwise, assigns its content into the global variable such as
windowandglobal.
For example, let's assume such a file print.js.
Case A
One can use it like:
<script type="module">
import print_things from "./print.js";
print_things("Javascript innovation");
</script>
Case B
or,
<script src="./print.js"></script>
<script>
print_things("Hmmmmmmm.");
</script>
Currently, using export makes the script throw an error in Case B: Uncaught SyntaxError: Unexpected token export. So it has to know whether export is available on the environment whereon it runs, in order to support the both use cases. How do I do this?