Javascript objects. I am trying to understand the difference between the following ways of class declaration. At a fundamental level is the difference between both of them? Is one advantageous over the other? if so, how?
1)
var Animal = function(){
this.run = function(speed){
console.log(speed)
};
this.eat = function(food){
console.log(food);
};
}
var dog = new Animal();
2)
var Animal = function(){};
Animal.prototype.run = function(speed){
console.log(speed)
};
Animal.prototype.eat = function(food){
console.log(food)
};