Possible Duplicate:
JavaScript: Class.method vs. Class.prototype.method
What’s the difference between creating a prototype like this:
Date.foo = function(bar) {
alert(bar);
};
And this:
Date.prototype.foo = function(bar) {
alert(bar);
};
Why/when should I use either?
in the first example, foo is a constructor method, its like a ‘static’ method in java. The second is like defining a method foo on a class — it is scoped to the instance.
you would access the first like
and the second like
or in another method on an instance of Date like