fengchuanyu 9 ماه پیش
والد
کامیت
7178c4836d
5فایلهای تغییر یافته به همراه248 افزوده شده و 0 حذف شده
  1. 45 0
      5_ES6/11_数组的扩展.html
  2. 74 0
      5_ES6/12_扩展运算符&剩余运算符.html
  3. 46 0
      5_ES6/13_函数扩展.html
  4. 20 0
      5_ES6/14_arguments.html
  5. 63 0
      5_ES6/15_this.html

+ 45 - 0
5_ES6/11_数组的扩展.html

@@ -0,0 +1,45 @@
+<!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>
+        // let aLi = document.getElementsByTagName("li");
+        // console.log(aLi);
+        
+        // 将类数组转换为真实数组
+        // let arr = Array.from(aLi);
+        // console.log(arr);
+
+        // let a = 1;
+        // let b = 2;
+        // let c = 3;
+
+        // 将一组值填入到数组当中
+        // let arr1 = Array.of(a,b,c,"a","b");
+        // console.log(arr1);
+
+        let arr = [1,2,3,4,5,6,7,8,9];
+
+        // arr.fill("a",4,7);
+        // arr.fill("a",4);
+        // console.log(arr);
+
+        // let arr2 = new Array(4);
+        // arr2.fill("a",0);
+        let arr2 = (new Array(10)).fill("a");
+        
+        console.log(arr2);
+    </script>
+</body>
+</html>

+ 74 - 0
5_ES6/12_扩展运算符&剩余运算符.html

@@ -0,0 +1,74 @@
+<!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 arr = [1,2,3,4,5,6,7,8,9];
+        // 利用扩展运算符实现一个浅拷贝
+        // let arr2 = [...arr];
+        // // let arr2 = arr;
+
+        // arr2[2] = "hello";
+
+        // console.log(arr2)
+        // console.log(arr);
+
+        // let arr = [1,2,3,4];
+        // let arr2 = [5,6,7,8];
+        // // let arr3 = arr.concat(arr2);
+        // let arr3 = [...arr,'你好',...arr2];
+        // arr2[0] = "hello";
+        // console.log(arr3,arr2);
+
+
+        // function foo(...arg){
+        //     console.log(arg)
+        // }
+        // foo(1,2,3,4)
+
+        // ... 剩余运算符 将除了已知的参数 剩余部分接受
+        // function foo(a,b,...arg){
+        //     console.log(a,b);
+        //     console.log(arg);
+        // }
+        // foo(1,2,4,5,6,7)
+
+        // 剩余运算符之用用作最后一个参数使用
+        // function foo(a,b,...arg,c){
+        //     console.log(a,b);
+        //     console.log(arg);
+        // }
+        // foo(1,2,4,5,6,7)
+
+
+        // let obj = {
+        //     a:1,
+        //     b:2
+        // }
+        // let obj2 = {
+        //     c:3,
+        //     d:4
+        // }
+        // let obj3 = {...obj,...obj2}
+        // console.log(obj3);
+
+        // let arr = ['a','b','c','d','e']
+
+        // let [a,b] = [...arr]
+        // console.log(a,b);
+
+        // let obj = {
+        //     a:1
+        // }
+        // let obj2 = {
+        //     b:2
+        // }
+        // let {a,b} = {...obj,...obj2}
+        // console.log(a,b);
+    </script>
+</body>
+</html>

+ 46 - 0
5_ES6/13_函数扩展.html

@@ -0,0 +1,46 @@
+<!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(){
+        //     console.log("hello");
+        // }
+        // var foo = function(){
+        //     console.log("hello");
+        // }
+
+        // 箭头函数内部没有arguments
+        // let foo = () => {
+        //     // console.log(arguments)
+        //     console.log("hello");
+        // };
+        // foo();
+
+
+        var a = 10;
+        // let obj = {
+        //     a : "hello",
+        //     foo:function(){
+        //         console.log(this.a)
+        //     }
+        // }
+        // 箭头函数内没有this
+        let obj = {
+            a : "hello",
+            foo:()=>{
+                console.log(this.a)
+            }
+        }
+
+        obj.foo()
+
+
+        
+    </script>
+</body>
+</html>

+ 20 - 0
5_ES6/14_arguments.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>
+        function foo(){
+            console.log(arguments)
+            for(var i=0;i<arguments.length;i++){
+                console.log(arguments[i]);
+            }
+            console.log(arguments.callee)
+        }
+        foo(1,2,3,4,5)
+    </script>
+</body>
+</html>

+ 63 - 0
5_ES6/15_this.html

@@ -0,0 +1,63 @@
+<!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>
+    <div id="box">hello world</div>
+    <script>
+        var oBox = document.getElementById("box");
+        // oBox.onclick = function(){
+        //     console.log(this.innerText);
+        // }
+
+        // oBox.onclick = function(){
+        //     console.log(this);
+        //     (function(){
+        //         console.log(this)
+        //     })()
+        // }
+        // 箭头函数内没有this概念 但是里面可以使用this this指向的是外层的this
+        oBox.onclick = function(){
+            console.log(this);
+            (()=>{
+                console.log(this)
+            })()
+        }
+
+        // var obj = {
+        //     a:10,
+        //     foo:function(){
+        //         console.log(this.a);
+        //     }
+        // }
+
+        // var a = 20;
+        // var obj = {
+        //     a:10,
+        //     foo:function(){
+        //         console.log(this.a);
+        //         (function(){
+        //             console.log(this.a)
+        //         })()
+        //     }
+        // }
+        // obj.foo();
+
+        // var a = 10;
+        // function foo2(){
+        //     var a = 1
+        //     console.log(this.a);
+        // }
+        // window.foo2();
+
+        // this 指向 : 指向调用当前函数的对象 要么指向window
+        // 对象当中方法默认指向当前对象 如果方法内有其他函数 ,其他函数内部的this指向window
+        // 普通函数this指向window
+
+
+    </script>
+</body>
+</html>