I'm a somewhat beginner, I used to know the very basics but stopped programming after that.
In JavaScript's Prototypal Inheritance, I've found/learned two ways of doing this.
Using the prototype
property of a constructor:
function Mammal(name) {
this.name = name,
this.order = "Mammal",
this.sayHi = function() {
console.log("My name is " + this.name);
}
}
function Cat(name) {
this.name = name;
this.family = "Felidae";
}
Cat.prototype = new Mammal();
let lion = new Cat("Lion");
Or by calling the Mammal.call(this, name)
method.
What are the differences between the two results? Which one is to be preferred if they're different?