JavaScript Introducing ES2015 The Cooler Parts of ES2015 Arrow Functions

Moses Wynn
Moses Wynn
16,363 Points

Why isn't Person a class?

How is Alena an instance of Person when Person is a function and not a class?

1 Answer

I'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.