zheng 5 zile în urmă
părinte
comite
4f70e5ed0b

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

@@ -20,6 +20,7 @@
         let c1 = Object.create(Father);
         let c2 = Object.create(Father);
         c1.list.push("99")
+        c1.aa = 12;
         console.log(c1,'c1')
         console.log(c2,'c2')
     </script>

+ 36 - 0
11.复习/15.寄生式继承.html

@@ -0,0 +1,36 @@
+<!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 createObj(x) {
+            let obj = Object.create(x);
+            obj.address = '哈尔滨';
+            obj.hi = function() {
+                console.log("大家好")
+            }
+            return obj;
+        }
+        let Father = {
+            name: '图图',
+            age: 3,
+            list: ['吃饭', '睡觉', '打豆豆'],
+            say() {
+                console.log("你好")
+            }
+        }
+        let c1 = createObj(Father);
+        let c2 = createObj(Father);
+        c1.list.push("99")
+        console.log(c1,'c1')
+        console.log(c2,'c2')
+    </script>
+</body>
+
+</html>

+ 57 - 0
11.复习/17.工厂模式.html

@@ -0,0 +1,57 @@
+<!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>
+    <!-- 
+        js五中设计模式:
+            单例模式
+            工厂模式
+            代理模式
+            装饰器模式
+            发布订阅模式
+    -->
+    <!-- 
+        工厂模式:
+            不使用new创建对象 由工厂函数/类统一对对象进行管理 例如创建 封装逻辑
+        缺点:
+            当模式过多时 工厂代码会显得臃肿
+        场景:
+            批量相似的对象 同意管理构造逻辑
+    -->
+        <script>
+            // admin
+            function Production(pName) {
+                this.name = pName;
+                this.role = '管理员';
+            }
+
+            // users
+            function User(uName) {
+                this.name = uName;
+                this.role = '用户';
+            }
+
+            function Info(type,name) {
+                switch(type) {
+                    case 'admin':
+                        return new Production(name);
+                    case 'users':
+                        return new User(name);
+                    default:
+                        throw new Error("传参错误");
+                }
+            }
+
+            let f1 = Info("admin","图图")
+            let f2 = Info("users","喜羊羊")
+            console.log(f1,'f1');
+            console.log(f2,'f2');
+
+
+        </script>
+</body>
+</html>