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 trialMoses Wynn
20,461 PointsWhy isn't Person a class?
How is Alena an instance of Person when Person is a function and not a class?
1 Answer
Miguel Barra
6,855 PointsI'm not an expert JavaScript developer but I was looking an explanation for this too and I think I got it. When we call a function with the "new" keyword the following happens:
- A new object will be created in the memory
- The scope of that object will be passed to the function; So the "this" keyword will refer to that object.
- The newly created object will be returned.
That's why a function works in the same way that a class. Classes just create a function. Actually there a lot of stuff happening under the hood because JavaScript is not an actual object-oriented programming language but a prototype-based language.