8.rest.html 564 B

123456789101112131415161718192021222324
  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(...rest)
  15. console.log(arguments)
  16. }
  17. fn1(1,2,3,4,5,6)
  18. function fn2(a,b,...c) {
  19. console.log(a,b,...c)
  20. }
  21. fn2(3,4,5,6,78,9)
  22. </script>
  23. </body>
  24. </html>