So I am going over a few lessons over JavaScript at CodeAcademy, and I ran into this section regarding prototypes.
A bit from the code:
function Dog(breed){
this.breed = breed;
};
Dog.prototype.bark = function(){
console.log("Bark!");
};
I don't understand the point of doing it that way. Why not just do it this way? (The way I first learned.)
function Dog(breed){
this.breed= breed;
this.bark = function(){
console.log("Bark!");
};
}
The second way, everything is together in one block, and not separated. What is the advantage of the first one? I know that there is, I'm just not seeing it.