STEP1 - we created a class by {}, then created vars and methods () inside the class. properties are assigned inside a constructor() method.
class Car {
constructor(name) {
this.brand = name;
}
present() {
return 'I have a ' + this.brand;
}
}
STEP2 - create instance of class.
const mycar = new Car("Ford");
STEP3 - we call class method by class instance.
mycar.present();
class Car {
constructor(name) {
this.brand = name;
}
present() {
return 'I have a ' + this.brand;
}
}
const mycar = new Car("Ford");
mycar.present();