zheng 5 päivää sitten
vanhempi
commit
63ec8e10be

+ 2 - 1
19.ts/index.html

@@ -7,6 +7,7 @@
 </head>
 <body>
     <!-- <script src="./1.ts" type="module"></script> -->
-     <script src="./类型/1.js"></script>
+     <!-- <script src="./类型/1.js"></script> -->
+      <script src="./面向对象/dist/1.类.js"></script>
 </body>
 </html>

+ 18 - 0
19.ts/面向对象/dist/1.类.js

@@ -0,0 +1,18 @@
+"use strict";
+/**
+ * 通过class定义一个类
+ */
+class Person {
+    say() {
+        console.log("你好");
+    }
+}
+Person.name1 = '图图';
+Person.age = 3;
+// 实例化
+let p1 = new Person();
+// p1.age = 12;
+console.log(p1, 'p1');
+Person.age = 12;
+console.log(Person.age);
+p1.say();

+ 26 - 0
19.ts/面向对象/src/1.类.ts

@@ -0,0 +1,26 @@
+/**
+ * 通过class定义一个类
+ */
+class Person {
+   readonly name1:string = '图图';
+   static age:number = 3;
+    say() {
+        console.log("你好")
+    }
+    /**
+     * static 静态属性 
+     * 属性添加static后 变成了 类
+     * 只能通过类 去更改 
+     * 规避name字段
+     * readonly 只读
+     */
+}
+
+// 实例化
+let p1 = new Person();
+// p1.age = 12;
+// p1.name1 = 'aaa';
+console.log(p1,'p1')
+Person.age = 12;
+console.log(Person.age)
+p1.say();

+ 18 - 0
19.ts/面向对象/src/2.构造函数和this.ts

@@ -0,0 +1,18 @@
+// let xxx = function() {}
+// function fn1() {}
+// (function(){})()
+// function fn2(() => {})
+// function Fn1() {
+// }
+// new Fn1()
+
+class Person1{
+    name2:string;
+    age2:number;
+    constructor(x:string,y:number) {
+        this.name2 = x;
+        this.age2 = y;
+    }
+}
+
+let p2 = new Person1('图图',3)

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

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