Suppose I have a module:
// module.js
export default function greet() { console.info( 'hello' ); }
If the module is loaded via:
<script type=module>
import greet from './module.js';
...
</script>
then I want the calling code to be able to invoke greet() on its own, without it being called automatically (the normal scenario).
However, if the module is loaded via:
<script type=module src="./module.js"></script>
then I want the module to invoke greet() immediately (as a side-effect of being loaded).
How can I accomplish this?