-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_class_5.html
More file actions
50 lines (35 loc) · 1.35 KB
/
2_class_5.html
File metadata and controls
50 lines (35 loc) · 1.35 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
<!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>
// Static properties and methods
// static을 사용하면 어디에 할당되어지는가?
// 얘도 아직 범용화 ㄴㄴ
class Article {
static publisher = 'Dream coding';
constructor(articleNumber) {
this.articleNumber = articleNumber;
}
static printPiblisher() {
console.log(Article.publisher);
}
}
const article1 = new Article(1);
const article2 = new Article(2);
// 우리가 스태틱을 사용하지않았다면, 해당 오브젝트의 값을 출력할 수 있었을것이다.
// 스태틱은 오브젝트마다 할당되어지는 것이 아니다.
// 클래스 자체에 할당되어진다.
console.log(article1.publisher); // undifined
console.log(article2.publisher); // undifined
// 그래서 static함수를호출 할 때 class에서 가져와애한다.
console.log(Article.publisher); // Dream coding
console.log(Article.publisher); // Dream coding
</script>
</body>
</html>