Экспорт и импорт из модуля
/*test.js*/
const add = (x, y) => {
return x + y
}
const subtract = (x, y) => {
return x - y;
}
var a = "a";
var b = "b";
export {a, b, subtract, add}
/*index.ejs*/
<script type="module">
import {add, subtract, a} from '/javascripts/test.js';
window.onload = function()
{
console.log(add(2, 3));
console.log(subtract(6,3));
console.log(a);
}
</script>
Javasper