zheng hace 5 días
padre
commit
894a163f38

+ 1 - 1
19.ts/index.html

@@ -8,6 +8,6 @@
 <body>
     <!-- <script src="./1.ts" type="module"></script> -->
      <!-- <script src="./类型/1.js"></script> -->
-      <script src="./面向对象/dist/3.继承.js"></script>
+      <script src="./面向对象/dist/5.接口.js"></script>
 </body>
 </html>

+ 1 - 0
19.ts/类型/2.ts

@@ -54,6 +54,7 @@ console.log(d.sex == Sex.man ? '男' : '女')
 //格式: type 名字 = 类型
 // 1.联合类型
 type Sex1 = "man" | "woman";
+// type Sex1
 let e:Sex1;
 e = "man";
 

+ 1 - 0
19.ts/面向对象/dist/3.继承.js

@@ -22,6 +22,7 @@
      * 因为想让多个子类 同时拥有父类的属性和方法 所以采用继承
      * 继承后子类就会拥有父类相同的内容
      * 若子类中定义的方法 与父类相同 则会覆盖父类的方法 称为:方法重新
+     * 若想添加新的方法 自行添加即可
      */
     // let parent1 = new Parent("图图",1)
     let a = new A("喜羊羊", 3);

+ 16 - 0
19.ts/面向对象/dist/4.super.js

@@ -0,0 +1,16 @@
+"use strict";
+(function () {
+    class Animal {
+        constructor(name) {
+            this.name = name;
+        }
+    }
+    class B extends Animal {
+        constructor(name, age) {
+            super(name);
+            this.age = age;
+        }
+    }
+    let b = new B("图图", 3);
+    console.log(b);
+})();

+ 18 - 0
19.ts/面向对象/dist/5.接口.js

@@ -0,0 +1,18 @@
+"use strict";
+(function () {
+    // 类型别名 接口区别
+    // 接口:定义数据类型的规范
+    // 类实现接口 需要继承
+    // 类型约束
+    class List {
+        constructor(name, age, address, sex, x) {
+            this.name = name;
+            this.age = age;
+            this.address = address;
+            this.sex = sex;
+            this.x = x;
+        }
+    }
+    let x = new List('图图', 3, '上海', '男', '12');
+    console.log(x);
+})();

+ 18 - 0
19.ts/面向对象/src/4.super.ts

@@ -0,0 +1,18 @@
+(function() {
+    class Animal {
+        name:string;
+        constructor(name:string) {
+            this.name = name;
+        }
+    }
+    class B extends Animal {
+        age: number;
+        constructor(name:string,age:number) {
+            super(name)
+            this.age = age;
+        }  
+    }
+
+    let b = new B("图图",3)
+    console.log(b)
+})()

+ 39 - 0
19.ts/面向对象/src/5.接口.ts

@@ -0,0 +1,39 @@
+(function () {
+    /**
+     * 类型别名 接口区别
+     * 接口:偏向 对象/结构的定义 可扩展 可合并
+     * 类型别名:偏向于任意类型 联合/交叉类型 简单的别名
+     * */
+
+    // 接口:定义数据类型的规范
+    // interface  status = 1|2|3;
+    // 接口声明
+    interface xxx {
+        name: string,
+        age: number,
+        address: string,
+        sex: string
+    }
+    interface xxx {
+        sex: string
+    }
+    // 类实现接口 需要继承
+    // 类型约束
+    class List implements xxx {
+        name: string;
+        age: number;
+        address: string;
+        // sex: string;
+        x: string;
+        constructor(name: string, age: number, address: string, sex: string, x: string) {
+            this.name = name;
+            this.age = age;
+            this.address = address;
+            this.sex = sex;
+            this.x = x;
+        }
+    }
+    let x = new List('图图', 3, '上海', '12');
+    console.log(x);
+
+})()