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 1

Why is jim = new Person("Jim"); outside of the function Person?

Could you put that in the constructor function?

2 Answers

Hi Liz,

It looks like Person is an Object containing the argument Jim?- so jim is a variable defined with the value of an instance of the object Person(Jim).

So, in other words jim is now actually holding or containing that function Person(Jim) was defined there.

I hope that helps?

Well, for one, it would have nowhere to start.

Person is a function that constructs an object when called.

When you type:

jim = new Person("Jim");

You're using that function to construct a new object and set it to the variable jim. In this line, you actually call the function.

Constructors aside, in general, you wouldn't want to call a function from within itself.