I have a question in regards to classical inheritance vs prototypical inheritance. I wanted to see what is better?
Let's say we have a function called familyTree.
function familyTree(){
this.lastname = "xyz";
}
If i want to add any additional details for them as far as I read, we can inherit parent in two ways:
1: prototypical way:
familyTree.prototype.personDetails = function(){
this.firstName = "abc";
this.middleName = "middle1";
var newToString = function(name){ //overwriting toString method
console.log("The name is: "+name+"Middle Name is "+middleName);
}
}
2: Classical way using 'new' keyword
var newPerson = new familyTree();
newPerson.firstName = "abc";
newPerson.middleName = "middle1";
newperson.newToString = function (name){
console.log("The name is: "+name+"Middle Name is "+middleName);
}
Let's say if I want to create 100 different middle names.
What makes more sense? Using Classical Inheritance or Prototypical? Because using Classical can copy over all the objects but using prototypical can get everything messy.
Please illustrate, when one should be using classical vs prototypical.