I have a function constructor defined this way:
var Person = function (name, yearOfBirth, job) {
this.name = name;
this.yearOfBirth = yearOfBirth;
this.job = job;
}
Person.prototype.calculateAge = function () {
console.log(2016 - this.yearOfBirth);
};
Now I also have another function constructor called Teacher which I've defined this way:
var Teacher = function (name, yearOfBirth, subject) {
Person.call(this, name, yearOfBirth, "teacher");
this.subject = subject;
}
Now I create a new object called roySir this way:
var roySir = new Teacher("Roy", 1960, "English");
However when I try to do roySir.calculateAge() I get an error saying that
"roySir.calculateAge is not a function"
How come the calculateAge function is not inherited here?
Another question I have is when I check:
roySir.hasOwnProperty("name") // true
Why is this true here? Isn't name a property of the parent class rather than an own property?


class- much easier to do