-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_class_2.html
More file actions
77 lines (54 loc) · 1.78 KB
/
2_class_2.html
File metadata and controls
77 lines (54 loc) · 1.78 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
<!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>
/*
[use strict]
Object-oriented programming
class : template
object : instance of a class
JavaScript classes
- introduced in ES6
- syntactical sugar over prototype-based inheritance
(기존에 존재하던 문법에 좀 더 편한 기능을 추가한걸 syntactical sugar라고 한다. )
*/
// class, object : 여러가지 타입의 값을 가지고 있으려고(그래서 함수도 넣을 수 있음)
// func : 타입을 일관성있게 계산하고 가지려고
// 1. Class declarations
class Person {
// constructor
constructor(name, age) {
//fields
this.name = name;
this.age = age;
}
//methods
speak(){
console.log(`${this.name} :hello!`);
}
}
const juye = new Person('juye',30); // 매개변수를 전달
console.log('age : '+ juye.age);
console.log('name : '+ juye.name);
console.log(juye)
juye.speak();
class Fruit {
constructor(color, size){
this.color = color;
this.size = size;
}
info(){
console.log(`${this.size}${this.color} fruit!`)
};
}
const apple = new Fruit('red', 'small');
console.log(apple);
</script>
</body>
</html>