-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweek4.html
More file actions
65 lines (59 loc) · 2.66 KB
/
Copy pathweek4.html
File metadata and controls
65 lines (59 loc) · 2.66 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 직접 객체 만들기
let objNewClass = new Object();
objNewClass.korName = "웹프로그래밍";
objNewClass.engName = "Web Programming";
objNewClass.classCode = "V024003";
objNewClass.nStudent = 0;
objNewClass.register = function () { this.nStudent++; };
objNewClass.unregister = function () { this.nStudent--; };
objNewClass.getStudentCount = function () { return this.nStudent; };
// 리터럴 표기
let objClass = {
korName: "웹프로그래밍",
engName: "Web Programming",
classCode: "V024003",
nStudent: 0,
register: function() { this.nStudent++; },
unregister: function() { this.nStudent--; },
getStudentCount: function() { return this.nStudent; }
};
// Prototype
function Class() {
this.korName = "웹프로그래밍";
this.engName = "Web Programming";
this.classCode = "V024003";
this.nStudent = 0;
}
Class.prototype.register = function () { this.nStudent++; };
Class.prototype.unregister = function () { this.nStudent--; };
Class.prototype.getStudentCount = function () { return this.nStudent; };
document.write("<h1>1. 직접 객체 만들기</h1>");
document.write("교과목 이름 = " + objNewClass.korName + "<br />");
document.write("등록 학생 수 = " + objNewClass.nStudent + "<br />");
objNewClass.register();
document.write("after register, 등록 학생 수 = " + objNewClass.nStudent + "<br />");
document.write("<hr>");
document.write("<h1>2. 리터럴 표기법</h1>");
document.write("교과목 이름 = " + objClass.korName + "<br />");
document.write("등록 학생 수 = " + objClass.nStudent + "<br />");
objClass.register();
document.write("after register, 등록 학생 수 = " + objClass.nStudent + "<br />");
document.write("<hr>");
var objProClass = new Class();
document.write("<h1>3. Prototype</h1>");
document.write("교과목 이름 = " + objProClass.korName + "<br />");
document.write("등록 학생 수 = " + objProClass.nStudent + "<br />");
objProClass.register();
document.write("after register, 등록 학생 수 = " + objProClass.nStudent + "<br />");
</script>
</body>
</html>