0

While working on an Angular JS App I found following block of code:

(function(){
    // code goes here
})();

Is it equivalent to window.onload or document.ready?

user4904589
  • 547
  • 2
  • 5
  • 15
  • 1
    No. It is called anonymous self-invoking function (function without name). – Sumanta736 Sep 16 '15 at 09:34
  • 1
    @Sumanta736 Immediately Invoked Function Expression aka `IIFE` – Tushar Sep 16 '15 at 09:35
  • @Tushar is it ok to have this multiple functions like this inside `document.ready`. Does it have cons? – guradio Sep 16 '15 at 09:36
  • 1
    @Pekka There's no pros of putting IIFE inside the `ready`, the `ready` handler also serves the purpose of IIFE – Tushar Sep 16 '15 at 09:38
  • @Tushar i see thank you for clarification. I have those for a reason that i dont want a global var so when two function need a var i use that to wrap the 2 functions.Its good to know that it does not harm the flow of code in anyway – guradio Sep 16 '15 at 09:40

0 Answers0