@@ -5,7 +5,7 @@ let a;
a = '12';
a = undefined;
console.log(a,'a')
-function fn1(a:any,b:any):any {
+function fn1(a:any,b:string):any {
console.log(a+b);
}
fn1(1,'76')
@@ -0,0 +1,23 @@
+// class 去声明类
+console.log("你好");
+class Person {
+ constructor() {
+ this.name = "John";
+ this.age = 10;
+ }
+ static say() {
+ console.log("大家好");
+}
+/***
+ * static 添加后 变成了类方法
+ * name 规避字段
+ * readonly 只读
+ */
+// 实例化对象
+let p = new Person();
+// p.name = '图图';
+// p.age = 12;
+// p.say();
+Person.say();
+console.log(new Person());
@@ -0,0 +1,18 @@
+// 构造函数 => 函数
+// function Fn1() {
+// }
+// Fn1();
+// new Fn1();
+// 构造函数:构造器(构造函数)(属性) 原型(方法)
+class Person1 {
+ constructor(name, age) {
+ this.name = name;
+ this.age = age;
+ console.log(this, 'this');
+ hello() {
+ console.log("你好");
+let p1 = new Person1('孙悟空', 20);
+p1.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,21 @@
+console.log("你好")
+ readonly name:string="John";
+ age:number =10;
+ console.log("大家好")
+console.log(new Person())
+ name:string;
+ age:number;
+ constructor(name,age) {
+ console.log(this,'this')
+ console.log("你好")
+
+let p1 = new Person1('孙悟空',20)
@@ -0,0 +1,12 @@
+{
+ "include": [
+ "./src/**/*"
+ ],
+ "compilerOptions": {
+ "moduleResolution": "Node",
+ "target": "ES2015",
+ "module": "ES2015",
+ "outDir": "./dist",
+ // "strict": true