0

It seems to me like this:

class Car {
    constructor(brand) {
        this.brand = brand;
        this.intro = function() {
            console.log("Hi! I am a " + this.brand + "!");
        }
    }
}

const car1 = new Car("BMW")

and this:

function car(brand) {
    this.brand = brand;
    this.intro = function() {
        console.log("Hi! I am a " + this.brand + "!");
    }
}

const car2 = new car("Mercedes")

are doing the exact same.

I feel like it didn't get the crucial point about classes here. Thank you very much!

Ray
  • 13
  • 2
  • 1
    FWIW, you shouldn't use `this.intro = function ...`, you should define that method on the prototype. Then you'd also see the simpler declaration when using `class`. – deceze Sep 28 '22 at 09:26

0 Answers0