Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,724 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