The script file embedded directly in the HTML file, the functions contained in the window
object. We can check with the following code.
for(let i in window)
{
if ((typeof window[i]).toString() === "function" && !window[i].toString().includes("[native code]"))
{
console.log(i);
console.log(window[i]);
console.log("nn");
}
}
But when I run a function indirectly by importing it from module
why isn’t it in there?
This is my file structure.
1. index.html
2. script.js
3. moduleScript.js
4. ModuleScript
- moduleScript01.js
- moduleScript02.js
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Event Listener</title>
<script src="moduleScript.js" type="module"></script>s
<script src="script.js"></script>
</head>
<body>
<script type="module" defer>
import * as moduleScript from "./moduleScript.js";
console.log(moduleScript.moduleScript01.Level01(1,2));
console.log(moduleScript.moduleScript02.Level02(1,2, 3));
console.log("nn");
for(let i in window)
{
if ((typeof window[i]).toString() === "function" && !window[i].toString().includes("[native code]"))
{
console.log(i);
console.log(window[i]);
console.log("nn");
}
}
</script>
</body>
</html>
script.js
function Level01 (a, b)
{
return a + b;
}
function Level02 (a, b, c)
{
return Level01(a,b) - c;
}
function Level03 (a, b)
{
return Level02(a,b, 1) * 5;
}
function print ()
{
console.log("Hello world");
}
moduleScript.js
export * as moduleScript01 from "./ModuleScript/moduleScript01.js";
export * as moduleScript02 from "./ModuleScript/moduleScript02.js";
moduleScript01.js
function Level01 (a, b)
{
return a + b;
}
export
{
Level01
}
moduleScript02
function Level02 (a, b, c)
{
return Level01(a,b) - c;
}
export
{
Level02
}