JSFiddle - React, Tailwind, and code Playground
by marcosc
JavaScript
function Vehicle() {
var registration = Math.random();
var prop = {
get: function() {
return registration
}
}
Object.defineProperty(this, "registration", prop)
}
//land vehicle travel on land, hence it has tires
function LandVehicle(numberOfTires, make) {
Vehicle.call(this);
if (!numberOfTires || isNaN(numberOfTires)) {
return;
}
var tires = [];
for (var i = 1; i <= numberOfTires; i++) {
var tire = new Tire(Math.random());
tires.push(tire);
}
var prop = {
get: function() {
return tires
}
}
Object.defineProperty(this, "tires", prop)
var prop = {
get: function() {
return make
}
}
Object.defineProperty(this, "make", prop)
//Tire factory
function Tire(pressure) {
var prop = {
get: function() {
return pressure
}
}
Object.defineProperty(this, "pressure", prop)
}
}
function MotorBike() {
var make = MotorBike.randomMake();
LandVehicle.call(this, 2, make);
this.topSpeed = 250;
}
//static functions
Object.defineProperty(MotorBike, "makes", {
get: function() {
return ["Honda", "Kawasaki", "Suzuki", "Yamaha"]
}
});
Object.defineProperty(MotorBike, "randomMake", {
value: getRandomMake
})
function getRandomMake() {
var rand = Math.round(this.makes.length * Math.random()) % this.makes.length;
return this.makes[rand];
}
function Car() {
//random make
var make = Car.randomMake();
LandVehicle.call(this, 4, make);
}
//static functions
Object.defineProperty(Car, "makes", {
get: function() {
return ["ferrari", "audi", "bmw", "honda", "ford"]
}
})
Object.defineProperty(Car, "randomMake", {
value: getRandomMake
})
function SportsCar() {
Car.call(this)
this.topSpeed = 300;
}
function RacingCar() {
SportsCar.call(this);
this.topSpeed =...