Possible Duplicate:
Use of 'prototype' vs. 'this' in Javascript?
I've seen both these two ways of declaring methods in Javascript:
var User = function() {
this.name = 'Foo';
this.greet = function() {
console.log('Hello!');
}
}
and
var User = function() {
this.name = 'Foo';
}
User.prototype.greet = function() {
console.log('Hello!');
}
What are the differences?