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 {
22 name ;
33 age ;
44
5+ constructor ( name , age ) {
6+ this . name = name ;
7+ this . age = age ;
8+ }
9+
510 introduceSelf ( ) {
611 document . write ( `私の名前は${ this . name } です。${ this . age } 歳です。` ) ;
712 }
@@ -10,14 +15,15 @@ class Student {
1015class SeniorStudent extends Student {
1116 researchQuestion ;
1217
18+ constructor ( name , age , researchQuestion ) {
19+ super ( name , age ) ;
20+ this . researchQuestion = researchQuestion ;
21+ }
22+
1323 introduceSelf ( ) {
1424 super . introduceSelf ( ) ;
1525 document . write ( `研究テーマは${ this . researchQuestion } です。` ) ;
1626 }
1727}
18-
19- const tanaka = new SeniorStudent ( ) ;
20- tanaka . age = 22 ;
21- tanaka . name = "田中" ;
22- tanaka . researchQuestion = "量子力学" ;
28+ const tanaka = new SeniorStudent ( "田中" , 22 , "量子力学" ) ;
2329tanaka . introduceSelf ( ) ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class Student {
1212
1313const tanaka = new Student ( ) ;
1414tanaka . name = "田中" ;
15- tanaka . age = 18 ;
15+ tanaka . age = 19 ;
1616tanaka . introduceSelf ( ) ;
1717tanaka . incrementAge ( ) ;
1818tanaka . introduceSelf ( ) ;
Original file line number Diff line number Diff line change @@ -119,13 +119,15 @@ tanaka.introduceSelf();
119119class Student {
120120 name;
121121 age;
122+
122123 introduceSelf () {
123124 document .write (` 私の名前は${ this .name } です。${ this .age } 歳です。` );
124125 }
125126 incrementAge () {
126127 this .age += 1 ;
127128 }
128129}
130+
129131const tanaka = new Student ();
130132tanaka .name = " 田中" ;
131133tanaka .age = 19 ;
@@ -296,6 +298,7 @@ class Student {
296298 document .write (` 私の名前は${ this .name } です。${ this .age } 歳です。` );
297299 }
298300}
301+
299302class SeniorStudent extends Student {
300303 researchQuestion;
301304
You can’t perform that action at this time.
0 commit comments