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

123
Vistas
Javascript checking if other dependencies have loaded

I have a bunch of modules loaded asynchronously in javascript but they depend on each other. I was trying to write the easiest way to verify that: a) the module exists b) it has fully initialized

and do all this in a minimally written way without a copy pasted function on each module.

My solution is to have a loaded array on each module and then define the code as such:

const Module2= (() => {
  const inited = {};

function init() {
    try {
      if (Module0.inited.init.true) Function.prototype();
      if (Module1.inited.init.true) Function.prototype();
    } catch (error) {
      setTimeout(init, 250);
      return;
    }
    ...do stuff...
    inited.init = {};
  }

  return {
    loaded,
    init,
    ...other funcs...
  };
})();

Module2.init();

Does anyone know of a shorter and more elegant way? To clarify, it is not sufficient to just check whether the module just exists, it has to also have been initialized (basically its init() needs to have finished).

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