fengchuanyu 10 godzin temu
rodzic
commit
bc2b35ced2
4 zmienionych plików z 144 dodań i 0 usunięć
  1. 3 0
      .vscode/settings.json
  2. 75 0
      8_ES6/22_箭头函数.html
  3. 31 0
      8_ES6/23_同步异步.html
  4. 35 0
      8_ES6/24_ajax.html

+ 3 - 0
.vscode/settings.json

@@ -0,0 +1,3 @@
+{
+    "liveServer.settings.port": 5501
+}

+ 75 - 0
8_ES6/22_箭头函数.html

@@ -0,0 +1,75 @@
+<!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>
+        // function foo(){
+        //     // ...
+        // }
+        // let foo2 = function(){
+        //     // ...
+        // }
+
+        // let foo3 = (a)=>{
+        //     console.log("hello",a);
+        // }
+        // foo3(1);
+
+
+        // let foo4 = ()=>{
+        //     console.log(this);
+        // }
+        // foo4();
+
+        // 箭头函数中的this指向的是定义时的上下文 而不是调用时的上下文
+        // 箭头函数内没有this
+        // let obj = {
+        //     a:1,
+        //     b:this,
+        //     foo(){
+        //         console.log(this);
+        //         // function foo5(){
+        //         //     console.log(this);
+        //         // }
+
+        //         let foo5 = ()=>{
+        //             console.log(this);
+        //         }
+        //         foo5()
+        //     },
+        //     foo2:()=>{
+        //         // console.log(this);
+        //     }
+        // }
+        // // console.log(obj.b);
+        // obj.foo();
+        // obj.foo2();
+
+
+        // function foo6(){
+        //     console.log(arguments);
+        // }
+
+        // foo6(1,2,3,4,5,6)
+
+        // 箭头函数内没有arguments
+        // let foo7 = (...arg)=>{
+        //     // console.log(arguments)
+        //     console.log(arg);
+        // }
+        // foo7(1,2,3,4,5,6)
+
+        // 箭头函数可以省略大括号 当箭头函数只有一条语句时 可以省略大括号 并且语句的执行结果就是函数的返回值
+        // let foo8 = ()=> 10;
+        // let res = foo8();
+        // console.log(res);
+
+
+
+    </script>
+</body>
+</html>

+ 31 - 0
8_ES6/23_同步异步.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>
+        // js 是单线程的 分为 同步任务 异步任务
+        // 同步任务 按照顺序执行 必须等待上一个任务执行完毕 才能执行下一个任务
+        // 异步任务 不按照顺序执行 不会阻塞后续任务的执行 会进入到任务队列中 等待同步任务执行完毕后 再执行异步任务
+        // console.log(3);
+        // setTimeout(function(){
+        //     console.log(1);
+        // },1000)
+        // console.log(2);
+
+        // js执行过程中无论异步代码需要等多久都会先执行同步任务
+        // 同步任务执行完毕后 才会执行异步任务
+
+        // 常见的异步方法:
+        // 定时函数 setTimeout setInterval
+        console.log(3);
+        setTimeout(function(){
+            console.log(1);
+        },0);
+        console.log(2);
+    </script>
+</body>
+</html>

+ 35 - 0
8_ES6/24_ajax.html

@@ -0,0 +1,35 @@
+<!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>
+        // ajax 异步请求
+        // 第一步 实例化一个XMLHttpRequest对象
+        let xhr = new XMLHttpRequest();
+        // 第二步 调用open方法 配置请求参数
+        // open方法参数说明
+        // 第一个参数:请求方法 GET/POST
+        // 第二个参数:请求地址
+        // 第三个参数:是否异步 true/false
+        xhr.open('GET',"https://api.thecatapi.com/v1/images/search",true);
+        // 第三步 调用send方法 发送请求
+        xhr.send();
+        // 第四步 监听状态变化
+        xhr.onreadystatechange = function(){
+            // 状态码 0 1 2 3 4
+            // 0: 请求未初始化 1: 服务器连接已建立 2: 请求已接收 3: 请求处理中 4: 请求已完成,且响应已就绪
+            if(xhr.readyState == 4){
+                // 状态码 200 表示请求成功
+                if(xhr.status == 200){
+                    // 响应体
+                    console.log(xhr.responseText);
+                }
+            }
+        }
+    </script>
+</body>
+</html>