-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_class_6.html
More file actions
93 lines (67 loc) · 2.7 KB
/
2_class_6.html
File metadata and controls
93 lines (67 loc) · 2.7 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// Inheritance 상속, 다양성
class Shape {
constructor(width, height, color) {
this.width = width;
this.height = height;
this.color = color;
}
// }
// draw() {
// console.log(`drawing ${this.color} color of`);
// }
// getArea() {
// return this.width * this.height;
// }
}
const a = new Shape(30,30,'green');
console.log(a);
console.log('----------------------------------------')
// // Shape상속를 상속받은 객체
// class Rectangle extends Shape{}
// class Triangle extends Shape{
// // 부모에게 상속받은 기능을 자식이 재정의함.
// draw() {
// super.draw(); // 하지만 부모의 기능도 super를 이용해서 사용 가능하다.
// console.log('삼각형');
// }
// getArea() {
// return (this.width * this.height) / 2 ;
// }
// }
// console.log('----------------------------------------')
// // Rectangle 객체에 값을 넣으면 상속받은 Shape 클래스의 틀을 사용가능.
// const rectangle = new Rectangle(20, 20, 'blue');
// rectangle.draw(); // drawing blue color of -> 함수도 사용가능
// console.log(rectangle.getArea()); // 400
// console.log('----------------------------------------')
// // Triangle class에서 상속받은 기능을 재정의하여 사용.
// const triangle = new Triangle(20, 20, 'green');
// triangle.draw();
// console.log(triangle.getArea());
// console.log('----------------------------------------')
// // Class checking : instanceOf
// // TRUE / FALSE 로
// // 왼쪽에있는 rectangle 오브젝트가
// // 오른쪽의 Rectangle class의 인스턴스인지 아닌지 말해줌
// console.log(rectangle instanceof Rectangle);
// console.log(triangle instanceof Rectangle);
// console.log(triangle instanceof Triangle);
// console.log(triangle instanceof Shape);
// console.log(triangle instanceof Object);
// // triangle은 Object의 인스턴스인가? T
// // 왜?
// // 자바스크립트에서 만든 모든 오브젝트는 Object에서 상속받은것이기때문에
// // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
</script>
</body>
</html>