接口(JS 中不存在)

//In Javascript there are no interfaces
class Car {
    constructor(started) {
        this.started = started;
        if (this.constructor.name === "Car") {
            throw new Error("Can't instantiate abstract class!");
        }
    }

    startEngine() {
        if (this.started
            return false;
        this.started = true;
        return true;
    }

    stopEngine() {
        this.started = false;
    }
}

class SportCar extends Car {}

let car = new SportCar();
console.log(car.startEngine());
console.log(car.startEngine());