11_ES6类.html 772 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. class Person{
  12. constructor(name){
  13. this.name = name
  14. }
  15. //方法
  16. eat(){
  17. console.log(this,'吃')
  18. }
  19. //类 方法 调用
  20. static say(){
  21. console.log(this,'xxxxxxxx')
  22. }
  23. }
  24. class Coder extends Person{
  25. constructor(name,age){
  26. super(name)
  27. this.age = age
  28. }
  29. }
  30. var p1 = new Person('zs')
  31. console.log(p1)
  32. Person.say()
  33. var a1 = new Coder('lisi',18)
  34. console.log(a1)
  35. a1.eat()
  36. </script>
  37. </body>
  38. </html>