12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- class Person{
- constructor(userName,userAge){
- this.userName = userName;
- this.userAge = userAge;
- }
- showName(){
- console.log(this.userName);
- }
- }
- // let p1 = new Person("小明",18);
- // console.log(p1.userAge);
- // p1.showName();
- class Student extends Person{
- constructor(userName,userAge,school){
- super(userName,userAge);
- this.school = school;
- }
- showSchool(){
- console.log(this.school);
- }
- }
- let s1 = new Student("小红",20,"黑工程");
- console.log(s1.userAge);
- s1.showName();
- console.log(s1.constructor)
- s1.showSchool();
- </script>
- </body>
- </html>
|