e 1 year ago
parent
commit
349c0b357c
2 changed files with 61 additions and 0 deletions
  1. 1 0
      JS高级/12.类.html
  2. 60 0
      JS高级/13.es6类+继承.html

+ 1 - 0
JS高级/12.类.html

@@ -29,6 +29,7 @@
       console.log(Person.prototype.constructor)
       function Fn1(name,age) {
         Person.call(this,name,age);
+        // Person.apply(this,[name,age]);
       }
       Fn1.prototype = new Person()
       Fn1.prototype.constructor = Fn1;

+ 60 - 0
JS高级/13.es6类+继承.html

@@ -0,0 +1,60 @@
+<!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>
+      /**
+       * ES6提供了class(类)的概念;
+       * 通过class定义关键字,可以是定义类
+       * class 定义类
+       * constructor 定义构造函数初始化
+       * extends 继承父类
+       * super 调用父级构造函数方法
+       * static 定义静态的方法和属性
+       */
+      // class定义类
+      class Phone {
+        // 构造函数
+        constructor(color,rain,holiday) {
+            this.color = color;
+            this.rain = rain;
+            this.holiday = holiday;
+        }
+        // 类的方法
+        call() {
+            console.log("打电话");
+        }
+        green() {
+            console.log("这是绿色")
+        }
+      }
+
+    //es6的继承
+    class newPhone extends Phone {
+        constructor(color,rain,holiday,book,vase){
+            super(color,rain,holiday);
+            this.book = book;
+            this.vase = vase;
+        }
+        music() {
+            console.log("音乐");
+        }
+        static end() {
+            console.log("结束");
+        }
+    }
+    var a1 = new Phone('红色','晴天','过年');
+    console.log(a1);
+    var a2 = new newPhone('12','23','34','掘金','花瓶');
+    console.log(a2,'a2');
+    a2.call();
+    a2.music();
+    newPhone.end();
+
+    </script>
+  </body>
+</html>