File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed
docs/2-browser-apps/03-class
inheritance-class-SeniorStudent Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,11 @@ class Student {
2
2
name ;
3
3
age ;
4
4
5
+ constructor ( name , age ) {
6
+ this . name = name ;
7
+ this . age = age ;
8
+ }
9
+
5
10
introduceSelf ( ) {
6
11
document . write ( `私の名前は${ this . name } です。${ this . age } 歳です。` ) ;
7
12
}
@@ -10,14 +15,15 @@ class Student {
10
15
class SeniorStudent extends Student {
11
16
researchQuestion ;
12
17
18
+ constructor ( name , age , researchQuestion ) {
19
+ super ( name , age ) ;
20
+ this . researchQuestion = researchQuestion ;
21
+ }
22
+
13
23
introduceSelf ( ) {
14
24
super . introduceSelf ( ) ;
15
25
document . write ( `研究テーマは${ this . researchQuestion } です。` ) ;
16
26
}
17
27
}
18
-
19
- const tanaka = new SeniorStudent ( ) ;
20
- tanaka . age = 22 ;
21
- tanaka . name = "田中" ;
22
- tanaka . researchQuestion = "量子力学" ;
28
+ const tanaka = new SeniorStudent ( "田中" , 22 , "量子力学" ) ;
23
29
tanaka . introduceSelf ( ) ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class Student {
12
12
13
13
const tanaka = new Student ( ) ;
14
14
tanaka . name = "田中" ;
15
- tanaka . age = 18 ;
15
+ tanaka . age = 19 ;
16
16
tanaka . introduceSelf ( ) ;
17
17
tanaka . incrementAge ( ) ;
18
18
tanaka . introduceSelf ( ) ;
Original file line number Diff line number Diff line change @@ -119,13 +119,15 @@ tanaka.introduceSelf();
119
119
class Student {
120
120
name;
121
121
age;
122
+
122
123
introduceSelf () {
123
124
document .write (` 私の名前は${ this .name } です。${ this .age } 歳です。` );
124
125
}
125
126
incrementAge () {
126
127
this .age += 1 ;
127
128
}
128
129
}
130
+
129
131
const tanaka = new Student ();
130
132
tanaka .name = " 田中" ;
131
133
tanaka .age = 19 ;
@@ -296,6 +298,7 @@ class Student {
296
298
document .write (` 私の名前は${ this .name } です。${ this .age } 歳です。` );
297
299
}
298
300
}
301
+
299
302
class SeniorStudent extends Student {
300
303
researchQuestion;
301
304
You can’t perform that action at this time.
0 commit comments