Oke, I have this working:
const personProto2 = {
calAge() {
console.log(2021 - this.birthday);
},
};
const rein = Object.create(personProto2);
rein.name = "Rein";
rein.birthday = 1945;
rein.calAge();
But if I do this:
const Person = function (name, birthday) {
this.name = name;
this.birthday = birthday;
};
Person.prototype.calAge = function () {
console.log(2021 - this.birthday);
};
const rein = Object.create(Person);
rein.name = "Rein";
rein.birthday = 1945;
rein.prototype.calAge();
It doesn't work. But a function is also a object. And a object has also a prototype.
So why the second example doesn't work?