Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript (2015) Prototypal Inheritance Setting Up the Prototype Chain

Andrew Chung
Andrew Chung
5,203 Points

Now set up the prototype chain for the Teacher prototype to inherit from the Person prototype.

So I really have no idea what to do here. Can anyone show me what the challenge wants me to do?

person.js
function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

Person.prototype.fullName = function() {
 return this.firstName + " " + this.lastName; 
};
teacher.js
function Teacher(firstName, lastName, roomNumber) { 
    Person.call(this, firstName, lastName); 
    this.room = roomNumber; 
}

3 Answers

geoffrey
geoffrey
28,736 Points

In fact, you just need to recall what Andrew shows earlier in the course. So, If you want a class to inherit the methods from another class, you need to use Object.create(), in this case, this way:

Teacher.prototype = Object.create(Person.prototype);
Andrew Chung
Andrew Chung
5,203 Points

Thanks, I've had the hardest time learning the material in this course.

Jeremy Barbe
Jeremy Barbe
8,728 Points

Me too Andrew....I don't know if it's me or the presentation of the material, but the entire prototype section of OOjs seems so convoluted.

I'm starting to think Andrew got the hardest courses to teach. Apparently there's no simple way to learn this stuff.
It's a lot to keep track of. Referring back and forth to different codes and objects, learning DRY...I keep looking at all the different comments, I guess the idea is just keep at it till it starts to make sense. I know some people just get it, I'm happy for them. The rest of us just need to persevere.

this is taking me a while took me like 10 mins beacuse i kept putting the code in wrong place i was putting inside the function ...lol