JS modules: import JS code
I recently found modules while recapping the ES6 lessons. Because I'm working on a JS project with already 1000+ lines I thought it might be useful to split the source code into multiple files to increase the maintainability. But when I looked JS modules up for more information I got a little confused because there seem to be at least three different possible ways to implement them: import/export, Components.utils.import() and AMD/CommonJS. Now I have following questions: 1. Can I simply include JS code (as library) into a JS file (without using a separate script tag). Or in other words, I just want to have one script tag that uses multiple files. 2. Which of the available solutions is the best way to do this (if possible) ?
3/12/2019 7:49:38 PMAaron Eberhardt
4 AnswersNew Answer
AMD – one of the most ancient module systems, initially implemented by the library require.js. CommonJS – the module system created for Node.JS server. UMD – one more module system, suggested as a universal one, compatible with AMD and CommonJS. Now all these slowly become a part of history, but we still can find them in old scripts. The language-level module system appeared in the standard in 2015, gradually evolved since then, and is now supported by all major browsers and in Node.js.
If you do not like to use es import export feature, you could form your own closure and release and export an object literal.
Thank you Calviղ, David Carroll and 4rontender for your helpful answers!