e 1 年之前
父節點
當前提交
bc59358330
共有 2 個文件被更改,包括 69 次插入0 次删除
  1. 40 0
      JS高级/7.类数组.html
  2. 29 0
      JS高级/8.rest.html

+ 40 - 0
JS高级/7.类数组.html

@@ -0,0 +1,40 @@
+<!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>内容一</li>
+        <li>内容二</li>
+        <li>内容三</li>
+        <li>内容四</li>
+    </ul>
+    <script>
+        /**
+         * 类数组:不能直接使用数组方法 
+         * 1.JavaScript中常见的类数组:arguments 
+         * 2.由querySelectorAll,getElementsByClassName,getElementsByTagName
+        */
+        var arr = [1,2,3,4,5,6];
+        // console.log(arr);
+        // function fn1() {
+        //     console.log(arguments);
+        // }
+        // fn1(arr);
+        // document.getElementsByTagName
+        // document.getElementsByClassName
+        // console.log(document.querySelectorAll("ul li"));
+        var news = document.querySelectorAll("ul li");
+        new.push("000");
+        console.log(news,'news');
+        // 类数组转成正常数组 
+        let list = [...news];
+        list.push("333");
+        console.log(list,'list');
+
+    </script>
+</body>
+</html>

+ 29 - 0
JS高级/8.rest.html

@@ -0,0 +1,29 @@
+<!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>
+        /**
+         * rest 用于获取函数中的实参 就是替代arguments的
+        */
+       function fn1(...rest) {
+        console.log(arguments,'实参1');
+        console.log(...arguments,'实参2');
+        console.log(rest,'4');
+        console.log(...rest,'3');
+       }
+       fn1(1,2,3,4,5,6);
+
+       function fn2(a,b,...c) {
+        console.log(a);//2
+        console.log(b);//3
+        console.log(...c); // 4,5,6,7,8,9,0,9999
+       }
+       fn2(2,3,4,5,6,7,8,9,0,9999);
+    </script>
+</body>
+</html>