11_es6类.html 804 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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('xxxxxxxxxxx')
  22. }
  23. }
  24. /* 继承 */
  25. class Coder extends Person {
  26. constructor(name,aa){
  27. super(name)
  28. this.aa = aa
  29. }
  30. }
  31. var p1 = new Person('zs')
  32. console.log(p1)
  33. p1.eat()
  34. Person.say()
  35. var c1 = new Coder('lisi','aaa')
  36. console.log(c1)
  37. Coder.say()
  38. </script>
  39. </body>
  40. </html>