title: JavaScript: Access between two functions defined in global scope
body: <p>can anyone explain the following to me. I have two JavaScript functions defined in global scope as follows:</p>
  
  <pre><code>    var foo = function () {
          var that = this;
  
          that.toString = function () { return "foobar" };
  
          return that;
      }();
  
      alert(foo.toString());
  
      var foo2 = function (foo) {
          var that;
  
          that = $.extend(true, {}, foo);
  
          return that;
      }();
  </code></pre>
  
  <p>Alerting foo.toString() works as I would expect as foo is assigned the result of invoking the function. However I would have expected foo2 to have access to foo.  Yet inside foo2 foo is undefined.  Can anyone help?</p>
  
  <p>Many Thanks,
  Mike.</p>