I've added a method calcAge
to jonas
, but why is it working for matilda
?
const Person = function (firstName, birthYear) {
this.firstName = firstName;
this.birthYear = birthYear;
};
const jonas = new Person('jonas', 1991);
const matilda = new Person('Matilda', 2017);
jonas.__proto__.calcAge = function () {
console.log(2037 - this.birthYear);
};
jonas.calcAge(); // 46
matilda.calcAge(); // 20