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

174
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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