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

158
Vistas
Self Invoking Function as jQuery ducument ready callback

What is the difference between

$(function() {
    // bind some event listeners
});

and

$(function() {
    // bind some event listeners
}());
about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

$(function() {
    // bind some event listeners
});

In above case the function is passed to the jquery which will get executed once document is ready.

$(function() {
    // bind some event listeners
}());

In above case the return of the function is passed to the jquery. Since the function is se3lf executing itself, it will get executed immediately and whatever the function returns will get passed to the jquery, so this is not a good way because the objective is to execute the function once document gets ready which is not happening in this case

about 4 years ago · Santiago Trujillo Denunciar

0

$(function(){...}); OR $(document).ready(function(){ ... });

This Function is called when the DOM is ready which means, you can start to query elements for instance. .ready() will use different ways on different browsers to make sure that the DOM really IS ready.

(function(){ ... })();

That is nothing else than a function that invokes itself as soon as possible when the browser is interpreting your JavaScript. Therefore, its very unlikely that you can successfully act on DOM elements here.

about 4 years ago · Santiago Trujillo Denunciar

0

$(function() {
    // bind some event listeners
});

This one will be executed only when the DOM is fully loaded, it's the shortcut for :

$(document).ready(function(){
  // Write code here
}); 

$(function() {
    // bind some event listeners
}());

This one is the same but the function inside the $() is a self invoking function. Usually the goal is to prevent variable name conflicts, because it's creating a new scope.

about 4 years ago · Santiago Trujillo 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