Skip to content

Commit beef302

Browse files
committed
Added inheritance demo
1 parent 051f1ca commit beef302

20 files changed

Lines changed: 128 additions & 0 deletions

File tree

File renamed without changes.
File renamed without changes.

ES6/Classes/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JavaScript</title>
6+
<script src="main.js"></script>
7+
</head>
8+
<body>
9+
10+
</body>
11+
</html>

ES6/Classes/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use strict";
2+
3+
class Person{
4+
5+
constructor(name, age, weight){
6+
this.name = name;
7+
this.age = age;
8+
this.weight = weight;
9+
}
10+
11+
displayWeight(){
12+
console.log(this.weight)
13+
}
14+
15+
}
16+
17+
let bucky = new Person('Bucky Roberts', 87, 562);
18+
bucky.displayWeight();
File renamed without changes.
File renamed without changes.

ES6/Inheritance/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Title
2+
3+
Description

ES6/Inheritance/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JavaScript</title>
6+
<script src="main.js"></script>
7+
</head>
8+
<body>
9+
10+
</body>
11+
</html>

ES6/Inheritance/main.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
3+
class Person{
4+
5+
constructor(name, age, weight){
6+
this.name = name;
7+
this.age = age;
8+
this.weight = weight;
9+
}
10+
11+
displayWeight(){
12+
console.log(this.weight)
13+
}
14+
15+
}
16+
17+
class Programmer extends Person{
18+
19+
constructor(name, age, weight, language){
20+
super(name, age, weight);
21+
this.language = language;
22+
}
23+
24+
displayAge(){
25+
console.log(this.age);
26+
}
27+
28+
displayLanguage(){
29+
console.log(this.language);
30+
}
31+
32+
}
33+
34+
let sally = new Person('Sally Jones', 32, 99);
35+
sally.displayWeight();
36+
37+
console.log('----------');
38+
39+
let bucky = new Programmer('Bucky Roberts', 87, 562, 'JavaScript');
40+
bucky.displayWeight();
41+
bucky.displayAge();
42+
bucky.displayLanguage();

0 commit comments

Comments
 (0)