8.rest.html 720 B

1234567891011121314151617181920212223242526272829
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. /**
  11. * rest 用于获取函数中的实参 就是替代arguments的
  12. */
  13. function fn1(...rest) {
  14. console.log(arguments,'实参1');
  15. console.log(...arguments,'实参2');
  16. console.log(rest,'4');
  17. console.log(...rest,'3');
  18. }
  19. fn1(1,2,3,4,5,6);
  20. function fn2(a,b,...c) {
  21. console.log(a);//2
  22. console.log(b);//3
  23. console.log(...c); // 4,5,6,7,8,9,0,9999
  24. }
  25. fn2(2,3,4,5,6,7,8,9,0,9999);
  26. </script>
  27. </body>
  28. </html>