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

167
Vistas
JavaScript: define a function inside file "foo" for use in imported file "bar"

I have a file (let's call it `foo`) that I import a module into using RequireJS (let's call it `bar`). Something like:
foo.js:

function doStuff() {
  require(['path/to/bar/'], function(bar) => { //code// })
}

However, bar calls a function (let's call it func) which is not defined in bar, only called in the code. How can I define func for use in bar? Something like:

bar.js

function doMoreStuff() {
  func()
}
foo.js

function doStuff() {
  require(['path/to/bar/'], function(bar) => { 
    bar.func = () => { console.log("hello world!") }
    bar.doMoreStuff()
  })
}

Note: I know bar.js isn't written as a module should be, pretend it is - everything works in my code but I get an error that the function isn't defined (because it isn't, hence the question on how to define it)

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