zheng 5 zile în urmă
părinte
comite
1429414e54
2 a modificat fișierele cu 43 adăugiri și 1 ștergeri
  1. 2 1
      11.复习/13.组合继承.html
  2. 41 0
      11.复习/16.寄生组合式继承.html

+ 2 - 1
11.复习/13.组合继承.html

@@ -27,10 +27,11 @@
             Person.call(this,val)
         }
         Child.prototype = new Person();
-        
+        Child.prototype.constructor = Child;
         let c1 = new Child('北京');
         let c2 = new Child('哈尔滨');
         c2.list.push("12");
+        console.log(c1.constructor,'打印');
         console.log(c1, 'c1', c1.list)
         console.log(c2, 'c2', c2.list)
         c1.say()

+ 41 - 0
11.复习/16.寄生组合式继承.html

@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+
+<body>
+    <script>
+        function Father(a) {
+            this.name = '图图';
+            this.list = ['吃饭', '睡觉', '打豆豆'];
+            this.address = a;
+        }
+        Father.prototype.say = function () {
+            console.log("你好");
+        }
+        function Child(val) {
+            Father.call(this,val);
+        }
+        // Child.prototype = new Father();
+
+        function createObj(c, f) {
+            c.prototype = Object.create(f.prototype);
+            c.prototype.constructor = c;
+
+        }
+        createObj(Child, Father)
+        let c1 = new Child('北京');
+        let c2 = new Child('哈尔滨');
+        c1.list.push("hahaha")
+        console.log(c1, 'c1');
+        console.log(c2, 'c2');
+        c1.say();
+        c2.say();
+    </script>
+</body>
+
+</html>