JSFiddle - React, Tailwind, and code Playground

by Ritesh Pandey

JavaScript

// Base class
function Bicycle(cadence, speed, gear) {
    this.cadence = cadence;
    this.speed = speed;
    this.gear = gear;
}

Bicycle.prototype.setCadence = function (cadence) {
    this.cadence = cadence;
}

Bicycle.prototype.setGear = function (gear) {
    this.gear = gear;
}

Bicycle.prototype.speedUp = function (increment) {
    this.speed += increment;
}

Bicycle.prototype.applyBrake = function (decrement) {
    this.speed -= decrement;
}

Bicycle.prototype.printStates = function () {
    console.log('cadence: ' + this.cadence);
    console.log('speed: ' + this.speed);
    console.log('gear: ' + this.gear);
}

// Derived class
function MountainBike(seatHeight, cadence, speed, gear) {
    Bicycle.call(this, cadence, speed, gear);
    this.seatHeight = seatHeight;
}

MountainBike.prototype = Bicycle.prototype;

MountainBike.prototype.setHeight = function (seatHeight) {
    this.seatHeight = seatHeight;
}