12_es6类.html 782 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. eat(){
  16. console.log(this,'吃')
  17. }
  18. //类方法 调用
  19. static say(){
  20. console.log('shuo')
  21. }
  22. }
  23. /* 继承 */
  24. class Coder extends Person {
  25. constructor(name,xx){
  26. super(name)
  27. this.xx = xx
  28. }
  29. }
  30. var p1 = new Person('zs')
  31. console.log(p1)
  32. p1.eat()
  33. Person.say()
  34. var c1 = new Coder('lisi','xxxx')
  35. console.log(c1)
  36. Coder.say()
  37. </script>
  38. </body>
  39. </html>