4 ms·
If you use normal includes instead of imports, and put an object (or better a closure) on the top as a namespace, your SPA will work with any browsers, and you
by bmacho 4y ago
If you use normal includes instead of imports, and put an object (or better a closure) on the top as a namespace, your SPA will work with any browsers, and you don't force your users to throw out their phones and laptops every 2-5 years.
- xps 4y agoYou could also just use a polyfill (es-module-shims) to add support for older browsers.
- deleted 4y ago[deleted]
- bmacho 4y agoMaybe you are right, and modules (even this fancy new module syntax) are not worth to fight against anymore. I don't really trust polyfill tho.
- thepra 4y agocould you make a code example?
- bmacho 4y agoI was thinking of including with <script src="mod.js"> </script> just how you include (or included in the past) jquery or mathjax. I manage my namespaces like function Zebras() { let l; //local let e; //has setter and getter gete = () => {return e} sete = (x) => {e = x} function lfunc() {console.log("local function")} function efunc() {console.log("exported function")} // exports : this.efunc = efunc this.gete = gete this.sete = sete } and import it <script src="mod.js"> </script> <script> zr = new Zebras() zr.sete(4) console.log( zr.gete() ) // 4 zr.efunc() // zr.lfunc() <- not working </script> You can export objects or functions trivially. I don't think you can expose primitives this way. I think this method is working since ~20 years, and will work 20 years from now, when you can't even get your bundlers to run. But then if you have to change it frequently, probably ES modules are easier to automate, test, and handle with bundlers.