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

173
Vistas
Calling a Javascript Function In a Module Type Script From A Normal Script

I am wondering if there is a way to call a Javascript Function that is inside a Module-type script from a normal script.

For example:

HTML:

<body>
   <button onclick="myFunction()">Click Here</button>
</body>

Normal Script:

function myFunction() {
   alert("Calling Module Function!");
   moduleFunction();
}

Module Script:

/// Module stuff that requires this to be a module script

function moduleFunction() {
   alert("This was called from inside a module script");
   // Info only accessible inside module script
}

I have tried the above code on my site, and I only get an Uncaught Reference error that the function name is not defined. Are there more steps I must take in order to use functions throughout the scripts?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could export from the module.js and import into the main.js, though both need to be <script type='module'>

/// Module.js
export function moduleFunction() {
   alert("This was called from inside a module script");
   // Info only accessible inside module script
}


// Main.js
import {moduleFunction} from Module.js

function myFunction() {
   alert("Calling Module Function!");
   moduleFunction();
}
 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

about 4 years ago · Juan Pablo Isaza Denunciar
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