Skip to content

Commit 163ef20

Browse files
node intro
Signed-off-by: Arnav Gupta <[email protected]>
1 parent b1eb2c0 commit 163ef20

File tree

10 files changed

+59
-4
lines changed

10 files changed

+59
-4
lines changed

Lecture09/oop-in-js/class.js

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ class Student extends Person {
1717
this.grade = grade
1818
}
1919
}
20+
21+
let s = new Student('Harry', 20, 10)

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="class.js"></script>
8+
<script src="prototype.js"></script>
99
</head>
1010
<body>
1111

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

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

99
let p = new Person('Jane', 40)
10+
console.log(p)

Lecture09/oop-in-js/prototype.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Person {
2+
constructor(name, age) {
3+
this.name = name
4+
this.age = age
5+
// this.isAdult = function () {
6+
// return this.age > 18
7+
// }
8+
}
9+
isAdult() {
10+
return this.age > 18
11+
}
12+
}
13+
14+
let p = new Person('Ken', 30)
15+
let p1 = new Person('Jane', 20)
16+
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script src="lib.js"></script>
9+
<script src="main.js"></script>
10+
</head>
11+
<body>
12+
13+
</body>
14+
</html>

Lecture10/browser-multifile/lib.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function add (a, b) {
2+
return a + b
3+
}

Lecture10/browser-multifile/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('sum of 1, 2', add(1,2))

Lecture10/node-intro/hello.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('Hello World')

Lecture10/node-multifile/lib.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function add (a, b) {
2+
return a + b
3+
}
4+
5+
function sub (a, b) {
6+
return a - b
7+
}
8+
9+
console.log(sub(3,4))
10+
11+
module.exports = {
12+
add
13+
}

Lecture10/node-multifile/main.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const lib = require('./lib')
2+
3+
console.log(' 1 + 2 = ', lib.add(1,2))
4+
console.log(' 1 - 2 = ', lib.sub(1,2))

0 commit comments

Comments
 (0)