zheng 1 week ago
parent
commit
87a56eaf6e

+ 12 - 1
11.ts/编译选项/dist/a.js

@@ -3,4 +3,15 @@ let a = 12;
 // document.getElementById
 // document
 // a = '12';
-console.log(this);
+// console.log(this);
+let b = {
+    name: "孙悟空"
+};
+function fn1() {
+    console.log(this);
+    return this.name;
+}
+var box = document.getElementById("box");
+box.addEventListener("click", function () {
+    console.log("盒子");
+});

+ 0 - 5
11.ts/编译选项/dist/happy.js

@@ -1,5 +0,0 @@
-console.log("你好");
-let a = 12;
-// document.getElementById
-// document
-console.log("哈哈");

+ 1 - 1
11.ts/编译选项/src/a.ts

@@ -15,4 +15,4 @@ function fn1() {
 var box = document.getElementById("box");
 box.addEventListener("click",function(){
     console.log("盒子")
-})
+})

+ 2 - 2
11.ts/编译选项/tsconfig.json

@@ -15,7 +15,7 @@
         // 规定ts生成那个版本的js
         "target": "es6",
         // 规定可以使用的库
-        "lib": ["dom"],
+        "lib": ["ES2015", "DOM"], 
         // 模式 "commonjs", "amd", "system", "umd", "es6", "es2015", "es2020", "esnext", "none", "es2022", "node16", "node18", "node20", "nodenext", "preserve"
         "module": "es2015",
         // 规定编译后的文件存放在哪个位置
@@ -26,7 +26,7 @@
         // 规定错误是否被编译
         "noEmitOnError": false,
         // 开启严格模式
-        "strict": true
+        // "strict": true
         // 规定是否允许使用this
         // "noImplicitThis": false,
         // // 检查是否存在空元素

+ 23 - 0
11.ts/面向对象/dist/1.类.js

@@ -0,0 +1,23 @@
+"use strict";
+/**
+ * 类 通过class定义
+ * tsc -w
+ * 属性:
+ * 属性名:类型 = 属性值
+ */
+class Person {
+    constructor() {
+        this.name = '孙悟空';
+    }
+    // 方法
+    say() {
+        console.log("你好");
+    }
+}
+Person.age = 23;
+// 实例化
+let p1 = new Person();
+console.log(Person.age, '1');
+// p1.name = '唐僧';
+console.log(p1.name, '2');
+p1.say();

+ 11 - 0
11.ts/面向对象/dist/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="./1.类.js"></script>
+</body>
+</html>

+ 24 - 0
11.ts/面向对象/src/1.类.ts

@@ -0,0 +1,24 @@
+/**
+ * 类 通过class定义
+ * tsc -w
+ * 属性:
+ * 属性名:类型 = 属性值
+ */
+class Person {
+    readonly name:string = '孙悟空';
+    static age:number = 23;
+
+    // 方法
+    say() {
+        console.log("你好")
+    }
+}
+
+// 实例化
+let p1 = new Person();
+
+console.log(Person.age,'1')
+// p1.name = '唐僧';
+
+console.log(p1.name,'2')
+p1.say()

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

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