25.继承3.0.html 801 B

123456789101112131415161718192021222324252627282930313233343536
  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. // 组合继承
  11. function Father() {
  12. this.name = '小明';
  13. this.arr = [1,2,3];
  14. this.fn1 = function() {
  15. console.log("这是组合继承");
  16. }
  17. }
  18. Father.prototype.getName = function() {
  19. return this.name;
  20. }
  21. function Child() {
  22. Father.call(this);
  23. this.color = 'red';
  24. }
  25. Child.prototype = new Father();
  26. Child.prototype.constructor = Child;
  27. var news = new Child();
  28. console.log(news);
  29. </script>
  30. </body>
  31. </html>