forked from impactbyte-fang/js-oop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop_2.js
More file actions
46 lines (37 loc) · 1 KB
/
oop_2.js
File metadata and controls
46 lines (37 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Vehicle {
constructor(weight = 0, price = 0) {
this.weight = weight // weight in kg
this.price = price // price in USD
}
get thisWeight() {
return `${this.weight} kg`
}
set setWeight(newWeight) {
if (typeof newWeight === "number") this.weight = newWeight
else return "Parameter is not a number!"
}
get thisPrice() {
return `USD ${this.price}`
}
set setPrice(newPrice) {
this.price = newPrice
}
}
class LandVehicle extends Vehicle {
constructor(weight, price, tires) {
super(weight, price)
this.tires = tires // number of tires
}
}
class WaterVehicle extends Vehicle {
constructor(weight, price, bouyancy) {
super(weight, price)
this.bouyancy = bouyancy // bouyancy level
}
}
const somethingToRide = new Vehicle(7, 120)
const somethingOnLand = new LandVehicle(7, 120, 2)
const somethingOnWater = new WaterVehicle(20, 200, 10)
// console.log((somethingOnWater.weight = 200))
// console.log(somethingOnWater.thisWeight)
console.log(Vehicle())