There are two ways (that I know of) to create a JavaScript object. Which way do you prefer and why?
/* METHOD 1 */
function Foo() {
this.Bar = function() {
alert("FooBar");
}
}
/* METHOD 2 */
function Foo() {
}
Foo.prototype.Bar = function() {
alert("FooBar");
}
I use the first method when I create my own objects because I find that it encapsulates the logic in a more readable fashion.