e 1 month ago
parent
commit
90366a6f9a

+ 3 - 3
14.ts/2.类型/1.ts

@@ -31,9 +31,9 @@ e = false;
  e = d;
 //  d = e;
 
-let f:string;
-f = '12';
-
+// let f:string;
+// f = '12';
+let f:string = 12;
 /**
  * any 与 unknown区别
  * any 可以给任意类型进行复制

+ 1 - 1
14.ts/3.编辑选项/dist/index.html

@@ -6,6 +6,6 @@
     <title>Document</title>
 </head>
 <body>
-    <script src="./part2.js"></script>
+    <script src="./part4.js"></script>
 </body>
 </html>

+ 3 - 0
14.ts/3.编辑选项/dist/part3.js

@@ -1 +1,4 @@
 export const flower = '槐花';
+let fl;
+fl = flower;
+console.log(fl, 'fl');

+ 2 - 0
14.ts/3.编辑选项/dist/part4.js

@@ -0,0 +1,2 @@
+import { flower } from './part3';
+console.log(flower, '哈哈哈');

+ 4 - 1
14.ts/3.编辑选项/src/a/part3.ts

@@ -1 +1,4 @@
-export const flower = '槐花';
+export const flower = '槐花';
+let fl:string;
+fl = flower;
+console.log(fl,'fl')

+ 2 - 0
14.ts/3.编辑选项/src/a/part4.ts

@@ -0,0 +1,2 @@
+import {flower} from './part3'
+console.log(flower,'哈哈哈')

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

@@ -0,0 +1,11 @@
+<!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="./src/2.构造函数.js"></script>
+</body>
+</html>

+ 29 - 0
14.ts/4.面向对象/src/1.类.js

@@ -0,0 +1,29 @@
+// 通过class取定义类
+// 对象:属性 方法
+var Person = /** @class */ (function () {
+    function Person() {
+        this.name = '孙悟空';
+        this.sex = '男';
+    }
+    /**
+     * static 添加后 变成了 类方法
+     * 通过类取进行调用
+     * 不能通过实例化后进行调用
+     * 规避name属性
+     * readonly 只读不修改
+     */
+    Person.sayHello = function () {
+        console.log("你好");
+    };
+    Person.age = 20;
+    return Person;
+}());
+var p = new Person();
+// p.name = '猪八戒'
+// console.log(p.)
+// p.sayHello()
+Person.sayHello();
+console.log(Person.age);
+// function Hi() {
+// }
+// let h = new Hi()

+ 29 - 0
14.ts/4.面向对象/src/1.类.ts

@@ -0,0 +1,29 @@
+// 通过class取定义类
+
+// 对象:属性 方法
+class Person {
+   readonly name:string = '孙悟空';
+   static age:number = 20;
+    sex:string = '男';
+    /**
+     * static 添加后 变成了 类方法
+     * 通过类取进行调用
+     * 不能通过实例化后进行调用
+     * 规避name属性
+     * readonly 只读不修改
+     */
+    static sayHello() {
+        console.log("你好")
+    }
+
+}
+let p = new Person();
+// p.name = '猪八戒'
+// console.log(p.)
+// p.sayHello()
+Person.sayHello()
+console.log(Person.age)
+// function Hi() {
+
+// }
+// let h = new Hi()

+ 26 - 0
14.ts/4.面向对象/src/2.构造函数.js

@@ -0,0 +1,26 @@
+/**
+ *  构造函数 => 函数
+    普通函数
+    function fn1() {
+    }
+    匿名函数
+    let fn2 = function() {
+    }
+    立即执行函数
+    (function() {
+    })()
+ */
+var Person1 = /** @class */ (function () {
+    function Person1(name, age) {
+        this.name = name;
+        // age = b;
+        this.age = age;
+    }
+    Person1.prototype.hello = function () {
+        console.log("你好我好大家好", this);
+    };
+    return Person1;
+}());
+var p1 = new Person1("孙悟空", 20);
+console.log(p1, 'p1', this);
+p1.hello();

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

@@ -0,0 +1,27 @@
+/**
+ *  构造函数 => 函数
+    普通函数
+    function fn1() {
+    }
+    匿名函数
+    let fn2 = function() {
+    }
+    立即执行函数
+    (function() {
+    })()
+ */
+class Person1 {
+  a: string;
+  age: number;
+  constructor(name:string, age) {
+    this.a = name;
+    // age = b;
+    this.age = age;
+  }
+  hello() {
+    console.log("你好我好大家好",this);
+  }
+}
+let p1 = new Person1(12, 20);
+console.log(p1,'p1',this)
+p1.hello()

+ 16 - 0
14.ts/4.面向对象/tsconfig.json

@@ -0,0 +1,16 @@
+{
+    "include": [
+        "./src/**/*"
+    ],
+    "compilerOptions": {
+        "moduleResolution": "Node",
+        "target": "ES6",
+        "module": "ES2015",
+        "lib": ["dom","ES2015"],
+        "outDir": "./dist",
+        "strict": true,
+        "noImplicitAny": false,
+        "noImplicitThis": false,
+        "noEmitOnError": true
+    }
+}