20_class.html 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. class Person{
  11. constructor(userName,userAge){
  12. this.userName = userName;
  13. this.userAge = userAge;
  14. }
  15. showName(){
  16. console.log(this.userName);
  17. }
  18. }
  19. // let p1 = new Person("小明",18);
  20. // console.log(p1.userAge);
  21. // p1.showName();
  22. class Student extends Person{
  23. constructor(userName,userAge,school){
  24. super(userName,userAge);
  25. this.school = school;
  26. }
  27. showSchool(){
  28. console.log(this.school);
  29. }
  30. }
  31. let s1 = new Student("小红",20,"黑工程");
  32. console.log(s1.userAge);
  33. s1.showName();
  34. console.log(s1.constructor)
  35. s1.showSchool();
  36. </script>
  37. </body>
  38. </html>