title: Javascript - Why calling function defined inside a closour?
body: <p>I have seen many js frameworks (including jquery) using closure around their main function scope. For example,</p>
  
  <pre><code>var obj = (function(){
      return {
          test : function(){
              alert('test');
          }
      }
  })();
  obj.test()
  </code></pre>
  
  <p>jquery source,
  <a href="http://code.jquery.com/jquery-1.7.2.js" rel="nofollow">http://code.jquery.com/jquery-1.7.2.js</a></p>
  
  <p>Whats the need that extra 'closure' around the 'function'? Or whats the difference if we are using it like,</p>
  
  <pre><code>var obj = function(){
      return {
          test : function(){
              alert('test');
          }
      }
  }();
  obj.test()
  </code></pre>
  
  <p>Both have the same behavior and function definition itself puts all the local variable inside a new scope... so why the extra closure? </p>