zheng hai 1 día
pai
achega
365fd4b637

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

@@ -0,0 +1,13 @@
+"use strict";
+class Person {
+    constructor() {
+        this.name = '图图';
+    }
+    say() {
+        console.log("你好");
+    }
+}
+Person.age = 10;
+let p = new Person();
+console.log(p, 'p', Person.age);
+p.say();

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

@@ -0,0 +1,15 @@
+"use strict";
+// function Person() {
+// }
+(function () {
+    class Person {
+        constructor(name, age) {
+            console.log(this, 'this1');
+            this.name = name;
+            this.age = age;
+            console.log(this, 'this2');
+        }
+    }
+    let p1 = new Person("孙悟空", 30);
+    let p2 = new Person("猪八戒", 40);
+})();

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

@@ -0,0 +1,30 @@
+"use strict";
+(function () {
+    class Person {
+        constructor(name, age) {
+            this.name = name;
+            this.age = age;
+        }
+        say() {
+            console.log("你好啊");
+        }
+    }
+    /**
+     * 因为想让多个子类同时拥有父类的属性和方法 所以采用继承
+     * 继承后 子类会拥有父类相同的内容
+     * 若子类中 定义的方法与父类相同 则会覆盖父类的方法 称为 方法重写
+     *
+     */
+    class A extends Person {
+        say() {
+            console.log("大家好");
+        }
+        back() {
+            console.log("返回");
+        }
+    }
+    let a1 = new A("孙悟空", 10);
+    console.log(a1, 'a1');
+    a1.say();
+    a1.back();
+})();

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

@@ -0,0 +1,28 @@
+"use strict";
+(function () {
+    class Person {
+        constructor(name, age) {
+            this.name = name;
+            this.age = age;
+        }
+        say() {
+            console.log("你好啊");
+        }
+    }
+    class A extends Person {
+        constructor(name, age, desc) {
+            super(name, age);
+            this.desc = desc;
+        }
+        say() {
+            console.log("大家好");
+        }
+        back() {
+            console.log("返回");
+        }
+    }
+    let a1 = new A("孙悟空", 10, '金箍棒');
+    console.log(a1, 'a1');
+    a1.say();
+    a1.back();
+})();

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

@@ -0,0 +1,16 @@
+<!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 src="./dist/4.super.js">
+
+    </script>
+</body>
+
+</html>

+ 12 - 0
15.ts/4.面向对象/src/1.类.ts

@@ -0,0 +1,12 @@
+class Person {
+    readonly name: string = '图图';
+    static age: number = 10;
+    say() {
+        console.log("你好")
+    }
+}
+
+let p = new Person();
+
+console.log(p, 'p', Person.age);
+p.say()

+ 19 - 0
15.ts/4.面向对象/src/2.构造函数.ts

@@ -0,0 +1,19 @@
+// function Person() {
+
+// }
+
+(function () {
+    class Person {
+        name: string;
+        age: number;
+        constructor(name: string, age: number) {
+            console.log(this, 'this1')
+            this.name = name;
+            this.age = age;
+            console.log(this, 'this2')
+        }
+    }
+
+    let p1 = new Person("孙悟空", 30);
+    let p2 = new Person("猪八戒", 40);
+})()

+ 31 - 0
15.ts/4.面向对象/src/3.继承.ts

@@ -0,0 +1,31 @@
+(function () {
+    class Person {
+        name: string;
+        age: number;
+        constructor(name: string, age: number) {
+            this.name = name;
+            this.age = age;
+        }
+        say() {
+            console.log("你好啊")
+        }
+    }
+    /**
+     * 因为想让多个子类同时拥有父类的属性和方法 所以采用继承
+     * 继承后 子类会拥有父类相同的内容
+     * 若子类中 定义的方法与父类相同 则会覆盖父类的方法 称为 方法重写
+     * 
+     */
+    class A extends Person {
+        say() {
+            console.log("大家好")
+        }
+        back() {
+            console.log("返回")
+        }
+    }
+    let a1 = new A("孙悟空", 10);
+    console.log(a1, 'a1')
+    a1.say()
+    a1.back();
+})()

+ 30 - 0
15.ts/4.面向对象/src/4.super.ts

@@ -0,0 +1,30 @@
+(function () {
+    class Person {
+        name: string;
+        age: number;
+        constructor(name: string, age: number) {
+            this.name = name;
+            this.age = age;
+        }
+        say() {
+            console.log("你好啊")
+        }
+    }
+    class A extends Person {
+        desc: string;
+        constructor(name: string, age: number, desc: string) {
+            super(name, age)
+            this.desc = desc;
+        }
+        say() {
+            console.log("大家好")
+        }
+        back() {
+            console.log("返回")
+        }
+    }
+    let a1 = new A("孙悟空", 10, '金箍棒');
+    console.log(a1, 'a1')
+    a1.say()
+    a1.back();
+})()

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

@@ -0,0 +1,17 @@
+{
+    "include": [
+        "./src/**/*"
+    ],
+    "compilerOptions": {
+        "target": "es2015",
+        "module": "es2015",
+        "lib": [
+            "DOM",
+            "ES2015"
+        ],
+        "outDir": "./dist",
+        "strict": true,
+        "noImplicitAny": false,
+        "noImplicitThis": false
+    }
+}