Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
¿Por qué las funciones se ejecutan en el archivo de script del módulo y no en el objeto de la ventana?

El archivo de script incrustado directamente en el archivo HTML, las funciones contenidas en el objeto de la window . Podemos comprobar con el siguiente código.

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

ingrese la descripción de la imagen aquí

Pero cuando ejecuto una función indirectamente al importarla desde el module ¿por qué no está allí? Esta es mi estructura de archivos.

 1. index.html 2. script.js 3. moduleScript.js 4. ModuleScript - moduleScript01.js - moduleScript02.js

índice.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>

guión.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"); }

móduloScript.js

 export * as moduleScript01 from "./ModuleScript/moduleScript01.js"; export * as moduleScript02 from "./ModuleScript/moduleScript02.js";

móduloScript01.js

 function Level01 (a, b) { return a + b; } export { Level01 }

móduloScript02

 function Level02 (a, b, c) { return Level01(a,b) - c; } export { Level02 }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!