@@ -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("盒子");
+});
@@ -1,5 +0,0 @@
-console.log("你好");
-let a = 12;
-// document.getElementById
-// document
-console.log("哈哈");
@@ -15,4 +15,4 @@ function fn1() {
var box = document.getElementById("box");
box.addEventListener("click",function(){
console.log("盒子")
-})
+})
@@ -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,
// // 检查是否存在空元素
@@ -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();
@@ -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>
@@ -0,0 +1,24 @@
+ readonly name:string = '孙悟空';
+ static age:number = 23;
+
+ console.log("你好")
+console.log(Person.age,'1')
+console.log(p1.name,'2')
+p1.say()
@@ -0,0 +1,15 @@
+{
+ "include": [
+ "./src/**/*"
+ ],
+ "compilerOptions": {
+ "target": "ES6",
+ "module": "ES2015",
+ "lib": ["dom","ES2015"],
+ "outDir": "./dist",
+ "strict": true,
+ "noImplicitThis": false,
+ "noImplicitAny": false,
+ "noEmitOnError": true