Difference between creating a global variable, vs one in a constructor function in JavaScript
<p>If I declare a global variable x as:</p>

<pre><code>var x = "I am window.x";
</code></pre>

<p>x will be a public property of the window object.
If I call a global function (without using "call", "apply" or attaching it to another object first), the window object will be passed in as the context (the “this” keyword).
It is like it is siting the x property on the current context, which happens to be the window.</p>

<p>If, however, I declare a variable in the same way inside a function, then use that function as a constructor, the property x will not be a public property of the object I just constructed (the current context).  I am happy (I know I can do this.x = …), but it just seems like a bit of a contradiction.</p>

<p>Have I misunderstood something (about it being a contradiction / different behaviour)?  Would anyone be able to explain what is going on, or is it just something I have to accept?</p>

<p>Hope that my question is clear.</p>
