zheng 6 天之前
父节点
当前提交
2efc1c2bae

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

@@ -0,0 +1,21 @@
+// class 去声明类 首字母大写
+// 属性 方法
+// readonly 只读
+// static 相当于 变成了类方法
+class Person {
+    constructor() {
+        this.name = '图图';
+        this.age = 10;
+    }
+    static say() {
+        console.log("你好");
+    }
+}
+// 使用类
+// new 进行类的实例化
+let p = new Person();
+console.log(p);
+// p.name = '小新';
+console.log(p.name);
+// p.say();
+Person.say();

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

@@ -0,0 +1,26 @@
+// 构造函数
+// function Fn1() {}
+// 通过new实例化:new Fn1()
+// 函数
+// function fn1() {}
+// (function(){})() 立即执行函数
+// 箭头函数() => xx
+// 匿名函数
+// let xxx =function() {}
+// 构造函数:构造器(属性) 原型(方法)
+// function Fn1() {
+// }
+class Person1 {
+    // 构造器
+    constructor(x, y) {
+        console.log(this);
+        this.name = x;
+        this.age = y;
+    }
+    hello() {
+        console.log("你好");
+    }
+}
+let p1 = new Person1('图图', 2);
+console.log(p1);
+p1.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>

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

@@ -0,0 +1,20 @@
+// class 去声明类 首字母大写
+// 属性 方法
+// readonly 只读
+// static 相当于 变成了类方法
+class Person {
+   readonly name:string = '图图';
+    age:number = 10;
+    static say() {
+        console.log("你好")
+    }
+}
+
+// 使用类
+// new 进行类的实例化
+let p = new Person();
+console.log(p)
+// p.name = '小新';
+console.log(p.name)
+// p.say();
+Person.say()

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

@@ -0,0 +1,28 @@
+// 构造函数
+// function Fn1() {}
+// 通过new实例化:new Fn1()
+// 函数
+// function fn1() {}
+// (function(){})() 立即执行函数
+// 箭头函数() => xx
+// 匿名函数
+// let xxx =function() {}
+// function Fn1() {
+// }
+// 构造函数:构造器(属性) 原型(方法)
+class Person1 {
+    name:string;age:number;
+    // 构造器
+    constructor(x:string,y:number) {
+        console.log(this)
+        this.name = x;
+        this.age = y;
+    }
+    hello() {
+        console.log("你好")
+    }
+}
+
+let p1 =new Person1('图图',2)
+console.log(p1)
+p1.hello();

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

@@ -0,0 +1,10 @@
+{
+    "include": [
+        "./src/**/*"
+    ],
+    "compilerOptions": {
+        "target": "es2015",
+        "module": "es2015",
+        "outDir": "./dist"
+    }
+}