fengchuanyu 8 months ago
parent
commit
3515bfe9ee

BIN
5_ES6/.DS_Store


+ 3 - 3
5_ES6/10_数组遍历方法.html

@@ -97,9 +97,9 @@
         //     console.log(obj[0],obj[1]);
         // }
 
-        for(let [index,val] of arr.entries()){
-            console.log(index,val);
-        }
+        // for(let [index,val] of arr.entries()){
+        //     console.log(index,val);
+        // }
 
 
     </script>

+ 2 - 2
5_ES6/15_this.html

@@ -96,8 +96,8 @@
         // foo.apply(obj,["world","你好"])
 
         // bind 它是将函数的this指向修改后返回一个函数,并不是立即执行。参数部分跟call方法一样
-        var foo2 = foo.bind(obj,"hello","你好")
-        foo2();
+        // var foo2 = foo.bind(obj,"hello","你好")
+        // foo2();
     </script>
 </body>
 </html>

+ 8 - 8
5_ES6/18_判断数据类型.html

@@ -44,14 +44,14 @@
         // console.log(boo.constructor == Boolean);
 
         // 方法四
-        console.log( Object.prototype.toString.call(und) );
-        console.log( Object.prototype.toString.call(nu) );
-        console.log( Object.prototype.toString.call(str) );
-        console.log( Object.prototype.toString.call(num) );
-        console.log( Object.prototype.toString.call(foo) );
-        console.log( Object.prototype.toString.call(boo) );
-        console.log( Object.prototype.toString.call(arr) );
-        console.log( Object.prototype.toString.call(obj) );
+        // console.log( Object.prototype.toString.call(und) );
+        // console.log( Object.prototype.toString.call(nu) );
+        // console.log( Object.prototype.toString.call(str) );
+        // console.log( Object.prototype.toString.call(num) );
+        // console.log( Object.prototype.toString.call(foo) );
+        // console.log( Object.prototype.toString.call(boo) );
+        // console.log( Object.prototype.toString.call(arr) );
+        // console.log( Object.prototype.toString.call(obj) );
 
 
 

+ 9 - 9
5_ES6/22_set.html

@@ -34,15 +34,15 @@
         // }
         // console.log(s4.size);
 
-        let obj = {
-            b:2
-        }
-        let ws = new WeakSet();
-        ws.add({a:1});
-        ws.add(obj);
-        // ws.add(1);
-        ws.add(obj);
-        console.log(ws)
+        // let obj = {
+        //     b:2
+        // }
+        // let ws = new WeakSet();
+        // ws.add({a:1});
+        // ws.add(obj);
+        // // ws.add(1);
+        // ws.add(obj);
+        // console.log(ws)
     </script>
 </body>
 </html>

+ 20 - 0
5_ES6/24_异步.html

@@ -0,0 +1,20 @@
+<!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>
+
+        var a = 10;
+        setTimeout(function(){
+            console.log(a)
+        }, 1000);
+        a++;
+        console.log(a)
+
+    </script>
+</body>
+</html>

+ 37 - 0
5_ES6/25_ajax.html

@@ -0,0 +1,37 @@
+<!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 ajaxFun(url,foo) {
+            // 第一步 创建XMLHttpRequest 对象;
+            var xmlh = new XMLHttpRequest();
+            // 第二步 发送请求
+            xmlh.open("GET", url, true);
+            xmlh.send();
+            // 第三步 处理请求结果
+            xmlh.onreadystatechange = function () {
+                if (xmlh.readyState == 4 && xmlh.status == 200) {
+                    var resObj = JSON.parse(xmlh.responseText)
+                    // console.log(resObj)
+                    // return resObj;
+                    foo(resObj)
+                }
+            }
+        }
+
+        // console.log(ajaxFun("./data/data1.json"));
+
+        ajaxFun("./data/data1.json",function(res){
+            console.log(res);
+        })
+    </script>
+</body>
+
+</html>

+ 4 - 4
5_ES6/7_结构赋值.html

@@ -79,10 +79,10 @@
         // var [a,b] = [b,a];
         // console.log(a,b);
         
-        var xiaomiPhoneJson = '{"title":"小米手机","price":4999,"pic":"xxxx.png"}';
-        var jsonObj = JSON.parse(xiaomiPhoneJson);
-        var {title} = jsonObj;
-        console.log(title);
+        // var xiaomiPhoneJson = '{"title":"小米手机","price":4999,"pic":"xxxx.png"}';
+        // var jsonObj = JSON.parse(xiaomiPhoneJson);
+        // var {title} = jsonObj;
+        // console.log(title);
         
         
     </script>

+ 6 - 6
5_ES6/9_块级作用域.html

@@ -16,12 +16,12 @@
         <li>5</li>
     </ul>
     <script>
-        var aLi = document.getElementsByTagName("li");
-        for(let i=0;i<aLi.length;i++){
-            aLi[i].onclick = function(){
-                console.log(i);
-            }
-        }
+        // var aLi = document.getElementsByTagName("li");
+        // for(let i=0;i<aLi.length;i++){
+        //     aLi[i].onclick = function(){
+        //         console.log(i);
+        //     }
+        // }
         // // 闭包 函数内部嵌套一个函数 内部函数可以调用外部函数的局部变量,这个变量不会消失 一直保存在内存当中
         // var aLi = document.getElementsByTagName("li");
         // for (var i = 0; i < aLi.length; i++) {

+ 16 - 0
5_ES6/ajax.js

@@ -0,0 +1,16 @@
+function ajaxFun(url,foo) {
+    // 第一步 创建XMLHttpRequest 对象;
+    var xmlh = new XMLHttpRequest();
+    // 第二步 发送请求
+    xmlh.open("GET", url, true);
+    xmlh.send();
+    // 第三步 处理请求结果
+    xmlh.onreadystatechange = function () {
+        if (xmlh.readyState == 4 && xmlh.status == 200) {
+            var resObj = JSON.parse(xmlh.responseText)
+            // console.log(resObj)
+            // return resObj;
+            foo(resObj)
+        }
+    }
+}

+ 38 - 0
5_ES6/data/data1.json

@@ -0,0 +1,38 @@
+{
+    "code": 101,
+    "message": "展示职位成功",
+    "data": [
+        {
+            "jrid": 59,
+            "levelname": "支行副行长"
+        },
+        {
+            "jrid": 60,
+            "levelname": "业务主管"
+        },
+        {
+            "jrid": 61,
+            "levelname": "业务副主管"
+        },
+        {
+            "jrid": 62,
+            "levelname": "高级柜员"
+        },
+        {
+            "jrid": 63,
+            "levelname": "中级柜员"
+        },
+        {
+            "jrid": 64,
+            "levelname": "普通柜员"
+        },
+        {
+            "jrid": 65,
+            "levelname": "实习生"
+        },
+        {
+            "jrid": 78,
+            "levelname": "水质监测员"
+        }
+    ]
+}

+ 38 - 0
5_ES6/data/data2.json

@@ -0,0 +1,38 @@
+{
+    "code": 101,
+    "message": "展示姓名成功",
+    "data": [
+        {
+            "jrid": 59,
+            "userName":"小张"
+        },
+        {
+            "jrid": 60,
+            "userName":"小李"
+        },
+        {
+            "jrid": 61,
+            "userName":"小王"
+        },
+        {
+            "jrid": 62,
+            "userName":"小赵"
+        },
+        {
+            "jrid": 63,
+            "userName":"小孙"
+        },
+        {
+            "jrid": 64,
+            "userName":"小周"
+        },
+        {
+            "jrid": 65,
+            "userName":"小陈"
+        },
+        {
+            "jrid": 78,
+            "userName":"小魏"
+        }
+    ]
+}

+ 1 - 1
5_ES6/练习题1_函数及变量特性.html

@@ -13,7 +13,7 @@
         // 第一题
         var n = 13;
         function fn(n) {
-            alert(n);
+            alert(n);//
             n = 14;
             alert(n);
         }

+ 1 - 1
5_ES6/练习题2_this指向.html

@@ -115,7 +115,7 @@
 
 
     var foo2 = foo.bind2(obj);
-    foo2()//hello
+    foo2()
   </script>
 </body>
 </html>

+ 12 - 12
5_ES6/练习题2_讲解.html

@@ -176,18 +176,18 @@
         // foo2()
 
         //9、补全下列代码
-        var o = { prop: 'loveCoding' };
-
-        function independent() {
-            return this.prop;
-        }
-        //在此补全代码
-
-        // o.f = independent.bind(o);
-        o.f = function(){
-            return independent.call(o)
-        }
-        console.log(o.f()); //  loveCoding
+        // var o = { prop: 'loveCoding' };
+
+        // function independent() {
+        //     return this.prop;
+        // }
+        // //在此补全代码
+
+        // // o.f = independent.bind(o);
+        // o.f = function(){
+        //     return independent.call(o)
+        // }
+        // console.log(o.f()); //  loveCoding
     </script>
 </body>
 

+ 54 - 0
5_ES6/练习题5_数组去重.html

@@ -8,7 +8,61 @@
 <body>
     <script>
         let arr = [ 1,2,3,'a',4,5,3,4,5,'a' ];
+        // 方法一 双循环 
+        // function unique(arr){
+        //     for(var i=0;i<arr.length;i++){
+        //         for(var j=i+1;j<arr.length;j++){
+        //             if(arr[i] == arr[j]){
+        //                 arr.splice(j,1)
+        //                 j--;
+        //             }
+        //         }
+        //     }
+        //     return arr;
+        // }
+        // console.log(unique(arr));
 
+        // 方法二 :indexOf 和 新数组
+        // function unique(arr){
+        //     var newArr = [];
+        //     for(var i=0;i<arr.length;i++){
+        //         if(arr.indexOf(arr[i]) == i){
+        //             newArr.push(arr[i])
+        //         }
+        //     }
+        //     return newArr;
+        // }
+        // console.log(unique(arr));
+
+        // 方法三 对象中key值不能重复
+
+        // var obj = {
+        //     a:"hell",
+        //     b:"world",
+        //     a:1
+        // }
+        // console.log(obj);
+        // function unique(arr){
+        //     var obj = {};
+
+        //     for(var i=0;i<arr.length;i++){
+        //         if(arr[i] in obj){
+        //             obj[arr[i]]++;
+        //         }else{
+        //             obj[arr[i]] = 1
+        //         }
+        //     }
+        //     // return obj;
+        //     return Object.keys(obj);
+        // }
+        // console.log(unique(arr));
+
+        // 方法四 es6
+        // function unique(arr){
+        //     return Array.from(new Set(arr)); 
+        // }
+        // console.log(unique(arr));
+        
     </script>
 </body>
 </html>

+ 16 - 0
5_ES6/练习题6_ajax.html

@@ -0,0 +1,16 @@
+<!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 src="./ajax.js"></script>
+    <script>
+        ajaxFun("./data/data1.json",function(res){
+            console.log(res);
+        })
+    </script>
+</body>
+</html>