The constructor function

Now one of the first things about a class that's really great is the ability to add a constructor function. A constructor function is a special function, it is specific to the class, automatically fires, and lets you initialize the instance of your class. In this case, we want to do something to customize an individual person when a new Person is created.

To define a constructor function we start with the name, constructor, but instead of adding a colon or anything else, we simply go right to our function arguments and right into the curly braces:

class Person {
  constructor () {
 
  }
}

This is our function, it's just like a regular function. The code inside is going to get executed and the brackets are our arguments, ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.