fengchuanyu 9 月之前
父節點
當前提交
7acc86d22d
共有 5 個文件被更改,包括 270 次插入5 次删除
  1. 1 1
      5_ES6/6_数值型扩展.html
  2. 57 4
      5_ES6/7_结构赋值.html
  3. 25 0
      5_ES6/8_JSON.html
  4. 93 0
      5_ES6/9_块级作用域.html
  5. 94 0
      5_ES6/练习题1-函数及变量特性.html

+ 1 - 1
5_ES6/6_数值型扩展.html

@@ -51,7 +51,7 @@
         // console.log(Number.isSafeInteger(Number.MAX_SAFE_INTEGER+1));
 
 
-        console.log(0.1+0.2);
+        // console.log(0.1+0.2);
 
 
 

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

@@ -7,7 +7,7 @@
 </head>
 <body>
     <script>
-        let arr = [1,2,3,4,5,6];
+        // let arr = [1,2,3,4,5,6];
         // a = 1;b = 2;c = 3;d = 4;....
         // let a = arr[0];let b = arr[1];let c = arr[2] .....
         // let [a,b,c,d,e,f] = arr;
@@ -27,11 +27,64 @@
         // console.log(personName,personAge);
 
 
-        let str = "hello";
-        let [a,b,c,d,e] = str;
+        // let str = "hello";
+        // let [a,b,c,d,e] = str;
 
-        console.log(a,b,c,d,e)
+        // console.log(a,b,c,d,e)
 
+
+        // 结构赋值应用场景
+        // function foo(o){
+        //     console.log(o.a+o.b);
+        // }
+
+        // function foo({a,b}){
+        //     console.log(a+b);
+        // }
+
+        // var obj = {
+        //     a:1,
+        //     b:2
+        // }
+
+        // foo(obj)
+
+        // function foo(){
+        //     var obj = {
+        //         userName:"小明",
+        //         userAge:18
+        //     }
+        //     return obj
+        // }
+
+        // var o = foo();
+        // console.log(o.userName,o.userAge);
+
+        // let {userName,userAge} = foo();
+        // console.log(userName,userAge);
+
+        // let a = 1;
+        // let b = 2;
+
+        // let c = 0;
+
+        // c = a;
+        // a = b;
+        // b = c;
+        // console.log(a,b);
+
+        // var a = 1;
+        // var b = 2;
+        
+        // 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);
+        
+        
     </script>
 </body>
 </html>

+ 25 - 0
5_ES6/8_JSON.html

@@ -0,0 +1,25 @@
+<!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 xiaomiPhone = {
+            title:"小米手机",
+            price:4999,
+            pic:"xxxx.png"
+        }
+        var xiaomiPhoneJson = '{"title":"小米手机","price":4999,"pic":"xxxx.png"}';
+        // var xiaomiPhoneJson = JSON.stringify(xiaomiPhone)
+        console.log(xiaomiPhone);
+        // 将对象转换为JSON格式 SON.stringify()
+        console.log(JSON.stringify(xiaomiPhone));
+        // console.log(xiaomiPhoneJson);
+        // 将JSON格式的字符串转换成对象JSON.parse()
+        console.log(JSON.parse(xiaomiPhoneJson));
+    </script>
+</body>
+</html>

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

@@ -0,0 +1,93 @@
+<!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>
+    <ul>
+        <li>1</li>
+        <li>2</li>
+        <li>3</li>
+        <li>4</li>
+        <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 (var i = 0; i < aLi.length; i++) {
+        //     (function (i) {
+        //         aLi[i].onclick = function () {
+        //             console.log(i)
+        //         }
+        //     }(i))
+        // }
+
+        // let a = 10;
+        // if(true){
+        //     console.log(a);
+        //     let a = "hello";
+        //     console.log(a)
+        // }
+
+
+
+        // var a = 10;
+
+        // function foo(){
+        //     var a;
+        //     console.log(a);
+        //     a = 20;
+        //     console.log(a);
+        // }
+        // foo();
+
+        // function foo(){
+        //     console.log(10);
+        // }
+        // foo()
+
+        // var foo = function(){
+        //     console.log(10);
+        // }
+        // console.log(foo)
+
+        // 立即执行函数
+        // (function(){
+        //     console.log(10);
+        // }())
+
+
+        // var a = 10;
+
+        // (function(){
+        //     var a = 20;
+        //     console.log(a)
+        // }())
+        // console.log(a)
+
+        // var a = 10
+        // function foo(){
+        //     var a = 20
+        //     return function(){
+        //         console.log(++a)
+        //     }
+        // }
+
+        // var foo2 = foo();
+        // console.log(foo2)
+        // foo2();
+        // foo2();
+    </script>
+</body>
+
+</html>

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

@@ -0,0 +1,94 @@
+<!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>
+        // 第一题
+        var n = 13;
+        function fn(n) {
+            alert(n);
+            n = 14;
+            alert(n);
+        }
+        fn(n);
+        alert(n)
+
+        // 第二题
+        var n = 0;
+        function a() {
+            var n = 10;
+            function b() {
+                n++;
+                alert(n);
+            }
+            b();
+        }
+        a();
+        alert(n);
+
+        // 第三题
+        console.log(num, str);
+        var num = 18;
+        var str = "lily";
+        function fn2() {
+            console.log(str, num);
+            num = 19;
+            str = "candy";
+            var num = 14;
+            console.log(str, num);
+        }
+        fn2();
+        console.log(str, num);
+
+        // 第四题
+        fn();
+        function fn() { console.log(1) };
+        fn();
+        var fn = 13;
+        fn();
+        function fn() { console.log(2) };
+        fn();
+
+        // 第五题
+        (function f() {
+            function f() { console.log(1) };
+            f();
+            function f() { console.log(2) };
+        })();
+
+        // 第六题
+        if (!("a" in window)) {
+            var a = 10;
+        }
+        alert(a);
+        console.log(fn);
+        if (9 == 8) {
+            function fn() {
+                alert(2);
+            }
+        }
+        
+        // 第七题
+        function fn() {
+            var i = 5;
+            return function (n) {
+                console.log(n * i++);
+            }
+        }
+        var f = fn();
+        f(4);
+        fn()(5);
+        f(6);
+
+
+    </script>
+</body>
+
+</html>