Using "new" in constructors, John Resig`s #35
<p>This is from John Resig`s Learning Advanced JavaScript #35 <a href="http://ejohn.org/apps/learn/#35" rel="nofollow">http://ejohn.org/apps/learn/#35</a> , called  What happens when we forget to use the new operator? </p>

<p>So he`s telling us that name variable (which I assume is window.name) gets overridden, but </p>

<p>1) is that overriding done inside the function User i.e. does <code>this.name</code> set a new global value for name?</p>

<p>2) how would have using "new User" (i.e. a constructor?) prevented overriding the window.name variable? is it because "new User" would only be an instance of User, but window.name is global?</p>

<p>Thanks if you can help explain. </p>

<pre><code>function User(first, last){ 
  this.name = first + " " + last; 
} 

window.name = "Resig"; 
var user = User("John", name); 

assert( name == "John Resig", "The name variable is accidentally overridden." );
</code></pre>
