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

92
Visualizações
Is it possible to reuse another function with a javascript file on the browser

In my html file when i click button it will call a function in file home.js.

File index.html:

<body>
   <button onclick="ShowMyAlert()"></button>
<script src="/js/home.js"></script>
</body>

And the funtion will call another function in file cUtilitiesForm.js. File home.js:

 var x = require('./cUtilitiesForm')

 function ShowMyAlert() {
     x.ShowAlertSuccess('Good job')
 }

File cUtilitiesForm.js:

function ShowAlertSuccess(title) {
       Swal.fire(
           `${title}`,
           'success'
       )
    }
module.exports = {
    ShowAlertSuccess: showAlertSuccess,
}

And then I click button it will give a error:

home.js:4 Uncaught TypeError: Cannot read properties of undefined 
(reading 'ShowAlertSuccess')
at ShowMyAlert (home.js:4)
at HTMLButtonElement.onclick ((index):52)

I don't know if this is possible or not

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