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 trialMoorthy Andy
6,754 PointsOOJavaScript stage 3 challenge- setting up the protype chain. need help with Person.call method.
Can' t figure out the Person.call(this, ????)
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.fullName = function() {
return this.firstName + " " + this.lastName;
};
function Teacher(firstName, lastName, roomNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.room = roomNumber;
}
2 Answers
Matthew Caloger
12,903 PointsWith function.call, you're inheriting the values of another function constructor. Because Person already defines the firstName and lastName properties, calling the Person function fills in the values for firstName and lastName (or whatever other common properties you have set).
function Teacher(firstName, lastName, roomNumber) {
Person.call(this, firstName, lastName);
this.room = roomNumber;
}
Note that after the "this" argument, call trails on and can fit in as many extra arguments as needed.
Steven Parker
231,275 PointsIt looks like you're on the right track.
So you realized you need to add something like "Person.call(this, ????)
" to the Teacher function, good so far. But you're not sure about what arguments to pass after "this"? Just take a look at the definition of Person. See what arguments it takes? Those are the same ones you will provide following "this" in the call method.
Calling the other constructor will replace some of the previous functionality of the Teacher method. But if you forget to remove it, the challenge should remind you.