e 1 anno fa
parent
commit
7f86b8109d

+ 4 - 0
ts/3.编译选项/dist/a.js

@@ -9,3 +9,7 @@ function fn1() {
     return this.name;
 }
 console.log(fn1.call(obj));
+var box = document.getElementById("box");
+box === null || box === void 0 ? void 0 : box.addEventListener("click", function () {
+    console.log("这是一个盒子");
+});

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

@@ -15,4 +15,9 @@ function fn1() {
     // return x+y;
     return this.name;
 }
-console.log(fn1.call(obj))
+console.log(fn1.call(obj))
+
+var box = document.getElementById("box");
+box?.addEventListener("click",function(){
+    console.log("这是一个盒子")
+})

+ 1 - 1
ts/3.编译选项/src/hello.js

@@ -1,2 +1,2 @@
 let a = 11;
-a = '11'
+a = '11';

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

@@ -31,7 +31,7 @@
         // 是否对js文件进行编译
         "allowJs": true,
         // checkJs 检查js文件是否符合编译规范
-        // "checkJs": false,
+        // "checkJs": true,
         //  removeComments 是否移除注释 默认false
         "removeComments": true,
         // noEmitOnError 规定错误是否允许编译
@@ -46,6 +46,6 @@
         // "noImplicitAny": false,
         // noImplicitThis 规定是否允许使用this
         // "noImplicitThis": false,
-        // "strictNullChecks": true
+        "strictNullChecks": true
     }
 }

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

@@ -0,0 +1,32 @@
+"use strict";
+// 通过class去定义一个类
+/**
+ * 对象中主要包含两部分:
+ * 属性 方法
+ */
+class Person {
+    constructor() {
+        this.name = '孙悟空';
+    }
+    /**
+     * static 添加后 变成了类方法
+     * 类时没有办法实例化
+     * 规避name字段
+     * readonly 只读不允许更改
+     */
+    // 方法
+    static say() {
+        console.log("大家好");
+    }
+}
+Person.age = 20;
+Person.ha = false;
+// console.log(
+//     Person.name)
+// 实例化对象
+let p = new Person();
+// p.name = '猪八戒';
+console.log(p);
+// console.log(Person.name)
+// p.say();
+Person.say();

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

@@ -0,0 +1,22 @@
+"use strict";
+// 构造函数 => 函数
+// function fn1() {
+//     console.log(this)
+// }
+// fn1();
+// new fn1();
+// 构造函数:原型 构造器
+class Person1 {
+    constructor(name, age) {
+        this.name = name;
+        this.age = age;
+        console.log(this);
+    }
+    hello() {
+        console.log(this, '哈哈哈');
+    }
+}
+let p1 = new Person1("孙悟空", 20);
+let p2 = new Person1("猪八戒", 22);
+p1.hello();
+// new Person1("孙悟空",20).hello();

+ 11 - 0
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="./dist/2.构造函数和this.js"></script>
+</body>
+</html>

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

@@ -0,0 +1,30 @@
+// 通过class去定义一个类
+/**
+ * 对象中主要包含两部分:
+ * 属性 方法
+ */
+
+class Person {
+    readonly name:string = '孙悟空';
+    static age:number = 20;
+    static ha:boolean = false;
+    /**
+     * static 添加后 变成了类方法
+     * 类时没有办法实例化
+     * 规避name字段
+     * readonly 只读不允许更改
+     */
+    // 方法
+   static say() {
+        console.log("大家好");
+    }
+}
+// console.log(
+//     Person.name)
+// 实例化对象
+let p =  new Person()
+// p.name = '猪八戒';
+console.log(p)
+// console.log(Person.name)
+// p.say();
+Person.say()

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

@@ -0,0 +1,27 @@
+// 构造函数 => 函数
+// function fn1() {
+//     console.log(this)
+// }
+// fn1();
+// new fn1();
+// 构造函数:原型 构造器
+
+class Person1 {
+  name: string;
+  age: number;
+  constructor(name:string,age:number) {
+    this.name = name;
+    this.age = age;
+    console.log(this)
+  }
+  hello() {
+    console.log(this,'哈哈哈')
+  }
+}
+
+let p1 =new Person1("孙悟空",20);
+let p2 =new Person1("猪八戒",22);
+
+p1.hello();
+
+// new Person1("孙悟空",20).hello();

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

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