title: best way to call $(document).ready() function
body: <p>I was wondering what was the best way to call a function when the DOM was ready. I mean, I know that </p>
  
  <pre><code>$(document).ready(function(){})
  </code></pre>
  
  <p>and </p>
  
  <pre><code>$(function(){})
  </code></pre>
  
  <p>were the same way to implement the action ready of the DOM.
  My question is more about performance, I usually wrote my JS like this : </p>
  
  <pre><code>$(document).ready(function(){
      console.log('Hello World');
  });
  </code></pre>
  
  <p>But a teacher once tryed to make me change my mind and write like this :</p>
  
  <pre><code>function main(){
      console.log('Hello World!');
  }
  $(document).ready(main);
  </code></pre>
  
  <p>The truth is I never did that but now I am wondering what is the best way in terms of performance... If I put everything in an external function does it load faster?</p>
  
  <p>In fact I was writting as the first way because I don't want my functions to be accessible from the DOM so I was doing this :</p>
  
  <pre><code>$(document).ready(function(){
      function Hello(){
              console.log('Hello World');
      }
      Hello();
  });
  </code></pre>
  
  <p>In this way it's impossible to use the function Hello from the DOM or from the console... And so I didn't like my teacher's way.
  But now I use to encapsulate all my code in an anonymous function and in this way I'm more cumfortable to write like this : </p>
  
  <pre><code>(function($){
      function Hello(){
          console.log('Hello World!');
      }
      $(document).ready(Hello);
  })(jQuery);
  </code></pre>
  
  <p>And that's why I was wondering about performance between the two methods, what do you guys think?</p>