寄生组合式继承

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>寄生组合式继承</title>
  </head>
  <body>
    <script>
      function Parent() {
        this.name = 'parent';
        this.play = [1, 2, 3];
      }
      function Child() {
        Parent.call(this);
        this.type = 'child';
      }
      Child.prototype = Object.create(Parent.prototype);
      Child.prototype.constructor = Child;

      function Parent1() {
        this.name = name;
        this.play = [1, 2, 3];
      }
      function Child1() {
        Parent1.call(this);
        this.type = 'child1';
      }
      Child1.prototype = Object.create(Parent1.prototype);
      Child1.prototype.constructor = Child1;
    </script>
  </body>
</html>

 

posted @ 2022-05-05 14:00  苹果π  阅读(11)  评论(0编辑  收藏  举报