Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!