15.寄生组合式继承.html 955 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>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. function Father(address1) {
  11. this.name = '图图';
  12. this.list = [1,2,3];
  13. this.address = address1;
  14. }
  15. Father.prototype.say = function () {
  16. console.log("你好")
  17. }
  18. function Child(address1) {
  19. Father.call(this,address1);
  20. this.age = 3;
  21. }
  22. // Child.prototype = new Father();
  23. function createObj(c, f) {
  24. c.prototype = Object.create(f.prototype);
  25. c.prototype.constructor = c;
  26. }
  27. createObj(Child, Father);
  28. let c1 = new Child('上海');
  29. let c2 = new Child('哈尔滨');
  30. c1.list.push("你好")
  31. console.log(c1)
  32. console.log(c2)
  33. </script>
  34. </body>
  35. </html>