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

100
Vistas
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 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