zheng 5 天之前
父节点
当前提交
b926a1aa6c
共有 2 个文件被更改,包括 68 次插入0 次删除
  1. 40 0
      11.复习/13.组合继承.html
  2. 28 0
      11.复习/14.原型式继承.html

+ 40 - 0
11.复习/13.组合继承.html

@@ -0,0 +1,40 @@
+<!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>
+    <!-- 
+        组合继承:
+            原型链继承 + 构造函数继承
+        实现:call/apply + 原型链
+    -->
+    <script>
+        function Person(x) {
+            this.x = x;
+            this.name = '图图';
+            this.age = 3;
+            this.list = ['吃饭', '睡觉', '打豆豆'];
+        }
+        Person.prototype.say = function () {
+            console.log("你好");
+        }
+        function Child(val) {
+            Person.call(this,val)
+        }
+        Child.prototype = new Person();
+        
+        let c1 = new Child('北京');
+        let c2 = new Child('哈尔滨');
+        c2.list.push("12");
+        console.log(c1, 'c1', c1.list)
+        console.log(c2, 'c2', c2.list)
+        c1.say()
+    </script>
+</body>
+
+</html>

+ 28 - 0
11.复习/14.原型式继承.html

@@ -0,0 +1,28 @@
+<!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>
+        let Father = {
+            name: '图图',
+            age: 3,
+            list: ['吃饭', '睡觉', '打豆豆'],
+            say() {
+                console.log("你好")
+            }
+        }
+        let c1 = Object.create(Father);
+        let c2 = Object.create(Father);
+        c1.list.push("99")
+        console.log(c1,'c1')
+        console.log(c2,'c2')
+    </script>
+</body>
+
+</html>