@@ -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("这是一个盒子");
+});
@@ -15,4 +15,9 @@ function fn1() {
// return x+y;
-console.log(fn1.call(obj))
+console.log(fn1.call(obj))
+
+box?.addEventListener("click",function(){
+ console.log("这是一个盒子")
+})
@@ -1,2 +1,2 @@
let a = 11;
-a = '11'
+a = '11';
@@ -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
@@ -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();
@@ -0,0 +1,22 @@
+// 构造函数 => 函数
+// 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();
@@ -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>
@@ -0,0 +1,30 @@
+ readonly name:string = '孙悟空';
+ static age:number = 20;
+ static ha:boolean = false;
+let p = new Person()
+console.log(p)
+Person.say()
@@ -0,0 +1,27 @@
+ name: string;
+ age: number;
+ constructor(name:string,age:number) {
+ console.log(this)
+ console.log(this,'哈哈哈')
+let p1 =new Person1("孙悟空",20);
+let p2 =new Person1("猪八戒",22);
@@ -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