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 JavaScript Foundations Objects Prototypes: Part 2

Kenn Hyatt
Kenn Hyatt
9,683 Points

Question about a certain line of code. Line 61 to be precise

Person.prototype = personPrototype; What specifically does this do?

This is what I reasoned: ".prototype" is a function in the javascript library. Jim called this function on the "Person" constructor function. "personPrototype" is then moved into and "overwrites?" the ".prototype" native function thus linking the prototype he created on line 43 to the object he created on line 57.

  1. Is this correct?
  2. Is this the code that creates the dynamic pointer?
  3. When he comments out "Person.prototype = personPrototype;" we can still see the name key but nothing else. Why is this?
Stacy Fabian
Stacy Fabian
2,246 Points

Hi Kenn,

Not sure if you've figured out an answer to this, but in case not...

It's a concept that an be a bit hard to explain in a comment but I'll see if I can do that.

Person.prototype is basically a safety net source for properties of the person object. It's not a function, it's a method (property-like item) of the person object.

Rather than just copy and paste from another source, I'm gonna point you to the Eloquent JavaScript book online at http://eloquentjavascript.net/Eloquent_JavaScript.pdf It's a great book that easily digestible. If you do a Command F/Ctrl F (search/find tool) for "prototypes" you'll come to a section that explains what a prototype is really nicely. (And in general this a great book for some JavaScript help).

I hope that helps with part of your question. If not, feel free to post again and maybe someone else can explain it well. I'm sorry it's not the best answer, but maybe I can point you in a direction of the answer. :)

Stacy