Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

288
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda