Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
Why are functions run in the module script file not in the window object?

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("\n\n");
        }
    }

enter image description here

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("\n\n");
        
        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("\n\n");
            }
        }
        
        
    </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
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda