e 1 year ago
parent
commit
6ba29b473e

+ 4 - 0
JS高级/25.继承3.0.html

@@ -27,6 +27,10 @@
         var news = new Child();
         console.log(news);
 
+        
+
+
+
     </script>
 </body>
 </html>

+ 0 - 1
JS高级/27.继承5.0.html

@@ -28,7 +28,6 @@
       }
 
       let child = Way(father);
-
       console.log(child.getColor());
       console.log(child.getName());
 

+ 2 - 1
JS高级/28.继承.6.0.html

@@ -22,12 +22,13 @@
         Father.call(this);
         this.color = "red";
       }
+      
       function Way(father,child) {
         child.prototype = Object.create(father.prototype);
         child.prototype.constructor = child;
       }
       Way(Father,Child);
-      
+
       Child.prototype.getColor = function() {
         return this.color;
       }

+ 93 - 0
JS高级/33.async await.html

@@ -0,0 +1,93 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Document</title>
+  </head>
+
+  <body>
+    <script>
+      /**
+       * async await
+       * async 在函数前添加async使函数变成异步 默认状态成功
+       * await 不仅局限于使用在async里 后面跟表达式 如果和async一起使用 await后的内容 属于微任务
+       */
+      
+       // async await 使用的是try{成功}catch{异常}
+      //await会阻塞后面的方法
+      
+    /***
+     * await 后 Promise时 进入微任务
+     * await 不是Promise 正常执行
+     * */
+    //   async function fn1() {
+    //     return 111;
+    //   }
+    //   fn1().then(val=>{
+    //     console.log(val,'val')
+    //   });
+
+    //   async function fn2() {
+    //     throw new Error("reject");
+    //   }
+    //   console.log(fn2());
+
+
+    //   fn1();
+    //   console.log(222);
+
+
+    function count(num) {
+        return new Promise((resolve,reject)=>{
+            setTimeout(()=>{
+                resolve(num * 2);
+            },1000)
+        })
+    }
+    async function fn3() {
+        let total1 = await count(2);
+        let total2 = await count(20);
+        let total3 = await count(12);
+        console.log(total1,total2,total3);
+    }
+    fn3();
+    console.log("333")
+  
+</script>
+</body>
+</html>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  

+ 110 - 0
JS高级/34.async await 练习.html

@@ -0,0 +1,110 @@
+<!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>
+        // async await 使用的是try{成功}catch{异常}
+      //await会阻塞后面的方法
+      //   async function fn1() {
+      //     console.log(1);
+      //     await fn2();
+      //     console.log(2);
+      //   }
+      //   async function fn2() {
+      //     console.log("fn2");
+      //   }
+      //   fn2();
+      //   console.log(3);
+
+      // 1 fn2 3 2
+
+      // async function async1() {
+      //   console.log('async1 start')
+      //   await async2()
+      //   console.log('async1 end')
+      //   setTimeout(() => {
+      //     console.log('timer1')
+      //   }, 300)
+      // }
+      // async function async2() {
+      //   setTimeout(() => {
+      //     console.log('timer2')
+      //   }, 400)
+      //   console.log('async2')
+      // }
+      // async1()
+      // setTimeout(() => {
+      //   console.log('timer3')
+      // }, 200)
+      // console.log('start')
+
+      //  async function fn1(){
+      //   console.log(333)
+      //   await fn2()
+      //   console.log(111)
+      // }
+      // async function fn2(){
+      //   throw new Error('rejected')
+      // }
+      // async function fn2(){
+      //   console.log(4)
+      // }
+      // fn1()
+      // console.log(2222)
+
+      //   async function fn1(){
+      //     console.log(1)
+      //     await fn2()
+      //     console.log(2) // 微1
+      //     setTimeout(()=>{ //宏1
+      //       console.log(3)
+      //     },1000)
+      //   }
+      //   async function fn2(){
+      //     console.log(4)
+      //     await fn3()
+      //     console.log(5) //微2
+      //     setTimeout(()=>{ //宏1
+      //       console.log(31)
+      //     },500)
+      //   }
+      //   async function fn3(){
+      //     setTimeout(()=>{
+      //       console.log(6) //宏2
+      //     },2000)
+      //   }
+      //   fn1()
+      //   console.log(7)
+
+    /***
+     * await 后 Promise时 进入微任务
+     * await 不是Promise 正常执行
+      //   async function a1() {
+      //     console.log(4)
+      //     await a2();
+      //     console.log(1)
+      //   }
+      //   async function a2() {
+      //     await console.log(2);
+      //     await console.log(7)
+      //   }
+      //   a1();
+    //   async function async1() {
+    //     await async2();
+    //     console.log("async1");
+    //     return "async1 success";
+    //   }
+    //   async function async2() {
+    //     return new Promise((resolve, reject) => {
+    //       console.log("async2");
+    //       reject("error");
+    //     });
+    //   }
+    //   async1().then((res) => console.log(res));
+    </script>
+  </body>
+</html>