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

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
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