@@ -0,0 +1,23 @@
+(function () {
+ /**
+ * abstract 与其他类差别不大
+ * 抽象类不是为了实例化对象
+ * 它是因为继承产生的
+ */
+ class Animal {
+ constructor(name) {
+ this.name = name;
+ }
+ class Child3 extends Animal {
+ say() {
+ console.log(`你好${this.name}`);
+ let c1 = new Child3("花花");
+ console.log(c1);
+ c1.say();
+ // let a1 = new Animal('图图');
+ // console.log(a1,'a1')
+ // a1.say()
+})();
@@ -0,0 +1,13 @@
+ // 使用接口
+ class Main {
+ // price: number;
+ constructor(name, color, price) {
+ this.color = color;
+ // this.price = price;
+ let m = new Main('牡丹', '红色', 100);
+ console.log(m);
@@ -6,6 +6,6 @@
<title>Document</title>
</head>
<body>
- <script src="./dist/4.super.js"></script>
+ <script src="./dist/6.接口.js"></script>
</body>
</html>
@@ -0,0 +1,28 @@
+(function(){
+ abstract class Animal {
+ name:string;
+ constructor(name:string) {
+ // say(){
+ // console.log("你好")
+ // }
+ abstract say():void
+ class Child3 extends Animal{
+ console.log(`你好${this.name}`)
+ c1.say()
+// let a1 = new Animal('图图');
+// console.log(a1,'a1')
+// a1.say()
+})()
+(function() {
+ // 定义接口
+ interface Flower {
+ color:string;
+ price?:number
+ class Main implements Flower {
+ color: string;
+ constructor(name:string,color:string,price:number){
+ let m = new Main('牡丹','红色',100)
+ console.log(m)