fengchuanyu 5 сар өмнө
parent
commit
8382ad2d5f

+ 19 - 4
6_ES6/20_继承.html

@@ -33,17 +33,32 @@
         // console.log(s1.userName);
         // console.log(s1.loveCoding);
         
-        // 原型继承 
+        // 原型继承 无法继承构造函数中的属性和方法
+        // function Student(userName,userAge,school) {
+        //     // this.userName = userName;
+        //     // this.userAge = userAge;
+        //     this.school = school;
+        // }
+        // Student.prototype = new Person();
+        // let s1 = new Student('张三',18,'清华大学');
+        // console.log(s1.loveCoding);
+        // console.log(s1.userName);
+        // s1.talk();
+
+        // 组合继承
         function Student(userName,userAge,school) {
-            this.userName = userName;
-            this.userAge = userAge;
+            // 构造函数继承 可以继承到构造函数中的属性和方法
+            Person.call(this,userName,userAge);
             this.school = school;
         }
+        // 原型继承 可以继承到原型上的属性和方法
         Student.prototype = new Person();
+        Student.prototype.constructor = Student;
         let s1 = new Student('张三',18,'清华大学');
         console.log(s1.loveCoding);
         console.log(s1.userName);
-        s1.talk();
+        console.log(s1.constructor);
+
     </script>
 </body>
 

+ 42 - 0
6_ES6/21_class.html

@@ -0,0 +1,42 @@
+<!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>
+        // 创建一个类 
+        class Person{
+            constructor(userName,userAge){
+                this.userName = userName;
+                this.userAge = userAge;
+            }
+            talk(){
+                console.log(`大家好我叫${this.userName}今年${this.userAge}岁了`);
+            }
+        }
+        // 实例化一个对象
+        // let p1 = new Person('张三',18);
+        // console.log(p1);
+        // p1.talk();
+
+        // 实现类的继承
+        class Student extends Person{
+            constructor(userName,userAage,school){
+                super(userName,userAage);
+                this.school = school;
+            }
+            sayHello(){
+                console.log("hello world");
+            }
+        }
+
+        let s1 = new Student('李四',18,'清华大学');
+        console.log(s1.userName);
+        s1.talk();
+        s1.sayHello();
+    </script>
+</body>
+</html>

+ 29 - 0
6_ES6/22_symbl.html

@@ -0,0 +1,29 @@
+<!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>
+        let num = Symbol();
+        let num2 = Symbol();
+        console.log(num);
+        let obj = {
+            userName:"张三",
+            age:20
+        }
+        obj[num] = "李四";
+        obj[num2] = "王五";
+
+        obj.age = 18;
+        console.log(obj);
+        console.log(obj[num]);
+        
+        for(let key in obj){
+            console.log(key);
+        }
+    </script>
+</body>
+</html>

+ 47 - 0
6_ES6/23_set.html

@@ -0,0 +1,47 @@
+<!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>
+        // Set 是一个类似数组的数据结构,但是成员的值都是唯一的,没有重复的值
+        // 创建一个set集合
+        // let set1 = new Set();
+        // set1.add('a');
+        // set1.add('b');
+        // set1.add('c');
+        // set1.add('d');
+        // 获取Set对象的尺寸
+        // console.log(set1.size)
+        // 删除Set对象中的值
+        // set1.delete('c');
+        // 判断Set对象中是否有某个值
+        // console.log(set1.has("d"));
+        // 清空Set对象
+        // set1.clear();
+
+        // for(let item of set1.entries()){
+        //     console.log(item);
+        // }
+        // set1.add("aa");
+        // console.log(set1);
+
+        // let arr = [1,2,3,4,5,5,6];
+        // let set2 = new Set(arr)
+        // console.log(set2);
+        
+        let ws1 = new WeakSet();
+        let obj = {
+            name:"张三"
+        }
+        ws1.add(obj);
+        ws1.add({name:"李四"});
+        ws1.add(obj);
+        console.log(ws1);
+        
+    </script>
+</body>
+</html>

+ 31 - 0
6_ES6/24_map.html

@@ -0,0 +1,31 @@
+<!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>
+        // let m1 = new Map();
+        // m1.set('a',1);
+        // m1.set('b',2);
+        // m1.set('c',3);
+        // m1.set('d',4);
+        // m1.delete("d");
+        // console.log(m1.has("a"));
+        
+        // console.log(m1.get("b"));
+        // m1.clear();
+        // console.log(m1.size);
+        // console.log(m1);
+
+        let wm1 = new WeakMap();
+        wm1.set({name:"张三"},1);
+        console.log(wm1);
+
+
+        var arr = [1,2,3,5,5,6,8,8,9];
+    </script>
+</body>
+</html>