使用arguments模拟重载

    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. // 使用arguments模拟重载
    11. function go(){
    12. if(arguments.length == 1){
    13. console.log(arguments[0])
    14. }else if(arguments.length == 2){
    15. console.log(arguments[0]+arguments[1])
    16. }
    17. }
    18. go(1)
    19. go(10,20)
    20. </script>
    21. </body>
    22. </html>

    1.PNG