During my free time, I like to dabble in JavaScript, but I’m currently struggling with this particular topic.
var person = new Person("Bob", "Smith", 52);
var teacher = new Teacher("Adam", "Greff", 209);
function Humans(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
function Person(firstName, lastName, age) {
Humans.call(this, firstName, lastName);
this.age = age;
}
Person.prototype = Object.create(Humans.prototype);
Person.prototype.fullDetail = function() {
return this.firstName + " " + this.lastName + " " + this.age;
};
function Teacher(firstName, lastName, roomNumber) {
Humans.call(this, firstName, lastName);
this.room = roomNumber;
}
Teacher.prototype = Object.create(Humans.prototype);
Teacher.prototype.fullDetail = function() {
return this.firstName + " " + this.lastName + " " + this.room;
};
// Here we call the fullDetail method of the person object
person.fullDetail();
Could anyone explain why person.fullDetail();
isn’t executing properly?
If you could provide some feedback and suggestions through your version of the code, it would be greatly appreciated. Thank you!