4 ms·
could you make a code example?
by thepra 4y ago
could 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.