Two ways of declaring methods in Javascript
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/310870/use-of-prototype-vs-this-in-javascript">Use of &#39;prototype&#39; vs. &#39;this&#39; in Javascript?</a>  </p>
</blockquote>



<p>I've seen both these two ways of declaring methods in Javascript:</p>

<pre><code>var User = function() {
    this.name = 'Foo';
    this.greet = function() {
        console.log('Hello!');
    }
}
</code></pre>

<p>and</p>

<pre><code>var User = function() {
    this.name = 'Foo';
}

User.prototype.greet = function() {
    console.log('Hello!');
}
</code></pre>

<p>What are the differences?</p>
