I am trying to understand How I can do inheritance in JavaScript properly. I can see that in many sources They do it using the create method as follows:
var ClassA = function() {
this.name = "class A";
}
ClassA.prototype.print = function() {
console.log(this.name);
}
var ClassB = function() {
this.name = "class B";
this.surname = "I'm the child";
}
ClassB.prototype = Object.create(ClassA.prototype);
....
However, I can see that I can extend from the parent object (ClassA) without using the create method, like that:
ClassB.prototype = ClassA.prototype;
So, Could Anyone tell me, why should I use the "Create" global method, as many examples do? In addition, in many examples They call the constructor of the base class (ClassA.call(this)), but I can see it is not really necessary. So?, I would appreciate your ideas. Thanks.