Repository navigation
Expand file tree
/
Copy path3-14.Class.html
More file actions
71 lines (58 loc) · 1.51 KB
/
Copy path3-14.Class.html
File metadata and controls
71 lines (58 loc) · 1.51 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<script>
//클래스 객체를 생성하기 위한 일종의 틀, 설계도.
//자동차
class Car {
constructor(modelName, modelYear, type, price) {
this.modelName = modelName;
this.modelYear = modelYear;
this.type = type;
this.price = price;
}
getModelName() {
return this.modelName;
}
getModelYear() {
return this.modelYear;
}
getPrice() {
return this.price;
}
setPrice(price) {
this.price = price;
}
}
let car = new Car("ionic", "2021", "e", 4000);
console.log(car.getModelName());
console.log(car.getModelYear());
console.log(car.getPrice());
car.setPrice(4100);
console.log(car.getPrice());
let car2 = new Car("genesis", "2021", "g", 6500);
console.log(car2.getModelName());
console.log(car2.getModelYear());
console.log(car2.getPrice());
class ElectronicCar extends Car {
constructor(modelName, modelYear, price) {
super(modelName, modelYear, "e", price);
// this.chargeTime = chargeTime;
}
setChargeTime(time) {
this.chargeTime = time;
}
getChargeTime() {
return this.chargeTime;
}
}
let eleCar1 = new ElectronicCar("ionic5", "2021", 4000);
eleCar1.setChargeTime(60);
console.log(eleCar1.getModelName());
console.log(eleCar1.getChargeTime());
</script>
</body>
</html>