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

126
Visualizações
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 à 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