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

140
Vistas
Will code after a jQuery ready() be guarantied to run before the ready function?

As titled!

ready() specifies that it loads after the DOM has been initialized and is ready for JS execution. However, I'm unsure of how that interacts with the JS itself!

If I have some JavaScript with the general format:

let functocall = () => {
    alert("Bad ending!");
};

// ... 

$(document).ready(() => {
    functocall();
});

// ...

functocall = () => {
    console.log("Safe!");
};

(note that the JS is loaded via a <script ... defer> in the head)

In this example, would it ever be possible for the document's ready function to be called and result in the alert() being called? On the examples I've tried, and the code I'm actually running, it never does, but I'm unsure if there's some edge case where it'd occur due to how the timing lines up.

I'd prefer it this way due to the following constraints:

  • functocall cannot be initialized with the other values
  • The ready() call being above the update is for code organization purposes (i.e. the lower section is a long chunk of code, and would be messy above the ready())
  • This JavaScript file is loaded with defer, to allow the libraries to load in first

I'd imagine I could just put the ready() into a function, and then call it and pass in the function, but I just personally think it'd look a bit worse that way, so I wanted to see if this was possible instead.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No. We don't know when the whole code is executed. It could be loaded after the document is ready, so the ready promise is resolved and the code will execute immediately.

about 4 years ago · Juan Pablo Isaza Denunciar
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