[HELP]Use class Syntax to Define a Constructor Function

Tell us what’s happening:
I managed to pass this test with the following code but still, I don’t know how this code works😒

I have two questions, please explain to me if you can.

1)What is the purpose of using makeClass() function here? and Why we are assigning it to const Vegetable?

2)How does constructor() works? and what does the following code indicates?


Your code so far

function makeClass() {
  "use strict";
  /* Alter code below this line */
    class Vegetable{
  /* Alter code above this line */
  return Vegetable;
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:

  1. Usually classes are self-standing and aren’t nested inside in another wrapper function. makeClass function was created probably just to show constructor can be wrapped.

  2. constructor is basically a factory. You can pass in whatever parameters inside and it will customize their products with corresponding variables. That code particular accepts a name parameter so you can give it any name and that instance of class will have that name.

Look here for more info.