0-readme edit

javascript-modules  edit

How to embed a javascript module file in another file.

How to embed a Javascript file (module) into another Javascript file

File to import: importedScriptModule.js


export default function () {
   ... javascript code here ...
}


Main file. Conditional and event listener are optional.


async function doSomethingUseful() {
    let { default: scriptmodule } = await import('./importedScriptModule.js');
    scriptmodule();
}
if ( .. conditional .. ) {
    doSomethingUseful();
    window.addEventListener('resize', doSomethingUseful);
}


Copy
Edit
<!-- components/0-readme/javascript-modules.php --> <div class="wm-ad-docs"> <h5>How to embed a Javascript file (module) into another Javascript file</h5> <p>File to import: importedScriptModule.js</p> <pre> <code> export default function () { ... javascript code here ... } </code> </pre> <p>Main file. Conditional and event listener are optional.</p> <pre> <code> async function doSomethingUseful() { let { default: scriptmodule } = await import('./importedScriptModule.js'); scriptmodule(); } if ( .. conditional .. ) { doSomethingUseful(); window.addEventListener('resize', doSomethingUseful); } </code> </pre> </div>
Copy
Copy
Edit
/* scss/0-readme/_javascript-modules.scss */