2.html 842 B

1234567891011121314151617181920212223242526272829303132333435363738
  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>构造函数继承</title>
  7. </head>
  8. <body>
  9. <script>
  10. function Father() {
  11. this.name = 'Lucy';
  12. this.arr = [1, 2, 3];
  13. this.fn1 = function () {
  14. console.log("哈哈哈")
  15. }
  16. }
  17. Father.prototype.say = function () {
  18. console.log("你好")
  19. }
  20. function Child() {
  21. this.age = 10;
  22. Father.apply(this)
  23. // Father.call(this)
  24. }
  25. const c1 = new Child();
  26. const c2 = new Child();
  27. c1.arr.push('00')
  28. console.log(c1, 'c1');
  29. console.log(c2, 'c2')
  30. // c2.say()
  31. c1.fn1()
  32. </script>
  33. </body>
  34. </html>