1234567891011121314151617181920212223242526272829 |
- <!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>
|