Skip to content

Commit b1eb2c0

Browse files
class syntax
Signed-off-by: Arnav Gupta <[email protected]>
1 parent b0ff487 commit b1eb2c0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Lecture09/oop-in-js/class.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Person {
2+
constructor(name, age) {
3+
this.name = name
4+
this.age = age
5+
}
6+
isAdult() {
7+
return this.age > 18
8+
}
9+
}
10+
11+
let p = new Person('Jane', 30)
12+
13+
14+
class Student extends Person {
15+
constructor(name, age, grade) {
16+
super(name, age)
17+
this.grade = grade
18+
}
19+
}

Lecture09/oop-in-js/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<title>Document</title>
8-
<script src="new-function.js"></script>
8+
<script src="class.js"></script>
99
</head>
1010
<body>
1111

Lecture09/oop-in-js/new-function.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
function Person(name, age) {
22
this.name = name
33
this.age = age
4+
this.isAdult = function () {
5+
return this.age > 18
6+
}
47
}
58

69
let p = new Person('Jane', 40)

0 commit comments

Comments
 (0)