e 4 月之前
父節點
當前提交
61220fe675

+ 21 - 0
14.ts/4.面向对象/dist/5.抽象类.js

@@ -0,0 +1,21 @@
+(function () {
+    /***
+     * 抽象类 与其他类差别不大
+     * abstract
+     * 抽象类不是为了实例化对象
+     * 他是因为要继承而产生的
+     */
+    class Animal {
+        constructor(name) {
+            this.name = name;
+        }
+    }
+    class Dog extends Animal {
+        say() {
+            console.log("我叫" + this.name);
+        }
+    }
+    let dog1 = new Dog('旺财a');
+    console.log(dog1, 'dog1');
+    dog1.say();
+})();

+ 21 - 0
14.ts/4.面向对象/dist/6.接口.js

@@ -0,0 +1,21 @@
+(function () {
+    // 类型定义数据
+    let obj = {
+        name: 'John Doe',
+        age: 30,
+        a: 12
+    };
+    // 使用接口
+    class Person {
+        constructor(color, types) {
+            this.color = color;
+            this.types = types;
+            // this.price = price;
+        }
+        say() {
+            console.log('走进来');
+        }
+    }
+    let p = new Person('红色', '牡丹');
+    console.log(p);
+})();

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

@@ -6,6 +6,6 @@
     <title>Document</title>
 </head>
 <body>
-    <script src="./dist/4.super.js"></script>
+    <script src="./dist/6.接口.js"></script>
 </body>
 </html>

+ 28 - 0
14.ts/4.面向对象/src/5.抽象类.ts

@@ -0,0 +1,28 @@
+(function() {
+    /***
+     * 抽象类 与其他类差别不大  
+     * abstract
+     * 抽象类不是为了实例化对象
+     * 他是因为要继承而产生的
+     */
+    abstract class Animal {
+        name:string;
+        constructor(name:string) {
+            this.name = name;
+        }
+        // 只能定义方法体
+        abstract say():void;
+        // say() {
+        //     console.log("你好啊")
+        // }
+    }
+    
+    class Dog extends Animal {
+        say() {
+            console.log("我叫"+this.name)
+        }
+    }
+    let dog1 = new Dog('旺财a');
+    console.log(dog1,'dog1')
+    dog1.say()
+})()

+ 37 - 0
14.ts/4.面向对象/src/6.接口.ts

@@ -0,0 +1,37 @@
+(function(){
+    type HH ={
+        name:string,
+        age:number,
+        a?:number
+    }
+    // 类型定义数据
+    let obj:HH = {
+        name: 'John Doe',
+        age: 30,
+        a:12
+    }  
+    
+    // 接口:换而言之  是一种定义数据的规范
+    interface flower {
+        color:string,
+        types:string
+    }
+    interface flower {
+        price?: number
+    }
+    // 使用接口
+    class Person implements flower {
+        color:string;
+        types:string;
+        constructor(color:string,types:string) {
+            this.color = color;
+            this.types = types;
+            // this.price = price;
+        }
+        say() {
+            console.log('走进来')
+        }   
+    }
+    let p = new Person('红色','牡丹');
+    console.log(p)
+})()