main.html
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<title>JavaScript: import declaration</title>
</head>
<script type="module">
// ----------------------------------------
//
// Note: relative references for the module's
// path must start with either "/", "./", or "../":
//
import cls, { clsTwo } from "./module.js";
let obj1 = new cls ( 42 );
let obj2 = new clsTwo("Hello World");
// ----------------------------------------
</script>
<body>
<pre id='out'></pre>
</body>
</html>
module.js
function print(line) {
document.getElementById('out').insertAdjacentText('beforeend', line+"\n");
}
class clsOne {
constructor(num) {
print("constructor of clsOne, num = " + num);
}
}
class clsTwo {
constructor(txt) {
print("constructor of clsTwo, txt = " + txt);
}
}
export { clsOne as default, clsTwo };