zheng hace 2 semanas
padre
commit
23e2fc226d

+ 0 - 1
15.ts/4.面向对象/dist/1.类.js

@@ -1,4 +1,3 @@
-"use strict";
 /**
  * 用class去声明类
  * 属性 方法

+ 0 - 1
15.ts/4.面向对象/dist/2.构造函数和this.js

@@ -1,4 +1,3 @@
-"use strict";
 /** 函数和构造函数的区别
  *  1.名称首字母大写:
  *    函数:小驼峰命名法

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

@@ -1,4 +1,3 @@
-"use strict";
 // 立即执行函数
 // function fn1() {}
 // fn1()

+ 0 - 1
15.ts/4.面向对象/dist/4.super.js

@@ -1,4 +1,3 @@
-"use strict";
 (function () {
     class Animal {
         constructor(name) {

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

@@ -1,4 +1,3 @@
-"use strict";
 (function () {
     /**
      * 抽象类 不能被实例化

+ 3 - 3
15.ts/4.面向对象/dist/6.接口.js

@@ -1,4 +1,3 @@
-"use strict";
 (function () {
     const obj = {
         name: '孙悟空',
@@ -6,11 +5,12 @@
     };
     console.log(obj);
     class Person5 {
-        constructor(name, age) {
+        constructor(name, age, sex) {
             this.name = name;
             this.age = age;
+            this.sex = sex;
         }
     }
-    let a = new Person5('猪八戒', 22);
+    let a = new Person5('猪八戒', 22, '男');
     console.log(a);
 })();

+ 51 - 0
15.ts/4.面向对象/dist/7.属性的封装.js

@@ -0,0 +1,51 @@
+(function () {
+    class Person {
+        constructor(name1, age1) {
+            this.name1 = name1;
+            this.age1 = age1;
+        }
+        /**
+         * get 获取
+         * set 设置
+         */
+        get aa() {
+            return this.name1;
+        }
+        set bb(val) {
+            this.name1 = val;
+        }
+    }
+    let p = new Person('孙悟空', 20);
+    console.log(p);
+    // Person.name1 = '你好'
+    // p.name1 = 'haha';
+    console.log(p, '111');
+    // p.aa()
+    console.log(p.aa);
+    p.bb = '大家好';
+    console.log(p);
+    // p.getName();
+    // console.log(Person)
+    class A {
+        constructor(num) {
+            this.num = num;
+        }
+        get num1() {
+            return this.num;
+        }
+        set num1(val) {
+            this.num = val;
+        }
+    }
+    class B extends A {
+        say() {
+            console.log(this.num);
+        }
+    }
+    let b = new B(10);
+    b.say();
+    // b.num= 20;
+    console.log(b);
+    b.num1 = 20;
+    console.log(b);
+})();

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

@@ -8,7 +8,7 @@
 </head>
 
 <body>
-    <script src="./dist/6.接口.js"></script>
+    <script src="./dist/7.属性的封装.js"></script>
     <!-- <script type="module"></script> -->
     <script>
         // function newPart() {

+ 60 - 0
15.ts/4.面向对象/src/7.属性的封装.ts

@@ -0,0 +1,60 @@
+(function () {
+    class Person {
+        name1: string;
+        age1: number;
+        constructor(name1: string, age1: number) {
+            this.name1 = name1;
+            this.age1 = age1;
+        }
+        /**
+         * get 获取
+         * set 设置
+         */
+        get aa() {
+            return this.name1;
+        }
+        set bb(val:string) {
+            this.name1 = val
+        }
+        // getName() {
+        //     return this.name1;
+        //     // console.log(this.name1,'name1')
+        // }
+    }
+    let p = new Person('孙悟空', 20);
+    console.log(p);
+    // Person.name1 = '你好'
+    // p.name1 = 'haha';
+    console.log(p, '111')
+    // p.aa()
+    console.log(p.aa)
+    p.bb = '大家好';
+    console.log(p)
+    // p.getName();
+    // console.log(Person)
+
+
+    class A {
+        protected num:number;
+        constructor(num:number) {
+            this.num = num;
+        }
+        get num1() {
+            return this.num;
+        }
+        set num1(val) {
+            this.num = val;
+        }
+    }
+    class B extends A {
+        say() {
+            console.log(this.num);
+        }
+    }
+    let b = new B(10);
+    b.say();
+    // b.num= 20;
+    console.log(b);
+    b.num1 = 20;
+    console.log(b);
+})()

+ 34 - 0
15.ts/4.面向对象/src/8.泛型.ts

@@ -0,0 +1,34 @@
+(function () {
+    // 泛型:先用字符去指代未知类型 使用时候传入具体的类型
+    // function fn1(value:number):number {
+    //     return value + 10;
+    // }
+    // fn1(12);  
+    function fn1<T>(value: T): T {
+        return value;
+    }
+    fn1(12);
+    fn1<string>('你好');
+
+    function fn2<T, K>(a: T, b: K): [T, K] {
+        return [a, b];
+    }
+    fn2(2, 3);
+
+    // 若函数中泛型继承接口 
+    interface happy {
+        jump: string;
+    }
+    function fn3<T extends happy>(a: T): T {
+        return a;
+    }
+    fn3({ jump: '12' })
+    // 若类中泛型继承接口 
+    class Ending<T extends happy> {
+        name: T;
+        constructor(name: T) {
+            this.name = name;
+        }
+    }
+    let end = new Ending({ jump: '12' })
+})()

+ 2 - 2
15.ts/4.面向对象/tsconfig.json

@@ -7,9 +7,9 @@
         "module": "es2015",
         "lib": ["dom","ES2015"],
         "outDir": "./dist",
-        "strict": true,
+        // "strict": true,
         "noImplicitAny": true,
         "noImplicitThis": true,
-        "noEmitOnError": true
+        // "noEmitOnError": true
     }
 }