zheng hai 1 día
pai
achega
c566db3d3a

+ 15 - 0
15.ts/4.面向对象/dist/5.接口.js

@@ -0,0 +1,15 @@
+"use strict";
+(function () {
+    class Person {
+        constructor(name, age) {
+            this.name = name;
+            this.age = age;
+        }
+        say() {
+            console.log('我叫' + this.name + ',今年' + this.age + '岁');
+        }
+    }
+    let p = new Person("图图", 3);
+    console.log(p, 'p');
+    p.say();
+})();

+ 1 - 1
15.ts/4.面向对象/index.html

@@ -8,7 +8,7 @@
 </head>
 
 <body>
-    <script src="./dist/4.super.js">
+    <script src="./dist/5.接口.js">
 
     </script>
 </body>

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

@@ -0,0 +1,39 @@
+(function () {
+    // 接口:定义数据的一种规范
+    interface sad {
+        name: string,
+        age: number
+    }
+    interface sad {
+        sex: string
+    }
+
+    // 联合类型
+    type x1 = string | number;
+
+    // interface 可以使用extends继承接口
+    // type 可以使用联合类型和交叉类型
+
+
+    class Person implements sad {
+        name: string;
+        age: number;
+        sex: string;
+        constructor(name: string, age: number, sex: string) {
+            this.name = name;
+            this.age = age
+            this.sex = sex;
+        }
+        say() {
+            console.log('我叫' + this.name + ',今年' + this.age + '岁')
+        }
+    }
+    let p = new Person("图图", 3, '男');
+    console.log(p, 'p');
+    p.say();
+
+
+    // type x1 = {
+    //     sex: string
+    // }
+})()