title: Javascript difference between calling a function and creating an instance of a function
body: <p>I am trying to understand why an inner function can access a public property of an outer function when the outer function is called directly, but not when it is assigned to a variable?</p>
  
  <p>Example:</p>
  
  <pre><code>function outer(x,y){
  
      this.x = x;
      this.y = y;
  
      function inner(){
          alert(this.x);       
      }
  
      inner();
  }
  
  outer(1,2); //As expected, alerts 1
  var func = outer(1,2) //Also alert 1
  var func2 = new outer(1,2); //Alerts undefined
  </code></pre>
  
  <p>One thing I tried was to remove the <code>this</code> keyword from <code>alert(this.x);</code> and it did work for all three cases.  However, if I do remove the <code>this</code> keyword, I'd be accessing the passed in param, not the public variable, which is definitely not the desired action.  Can someone explain this behavior? </p>