Classes in JS – ES 6

a simple example of class

class Car {
    constructor({title}) {
        this.title = title;
    }

    drive() {
        return 'driveeee...';
    }
}

const car = new Car({title: 'Toyota'});
console.log(car.drive());
console.log(car.title);

class Toyota extends Car {

    constructor(options) {
        super(options);
        this.color = options.color;
    }

    honk() {
        return 'beeeep';
    }
}

const toyota = new Toyota({color: 'red', title: 'wwrangler'});
console.log(toyota.honk());
console.log(toyota);

Leave a Comment

Your email address will not be published. Required fields are marked *