重载:函数名相同,参数不同 就是根据参数的不同,动态决定调用哪个方法
    js中没有重载的概念,因为重复声明,下面的会覆盖上面的

    1. // 使用function声明的方法,本质上是window的方法
    2. function go(a){
    3. console.log(a);
    4. }
    5. function go(a,b){
    6. console.log(a+b);
    7. }
    8. ==
    9. var go =function(a){
    10. console.log(a)
    11. }
    12. var go=function(a,b){
    13. console.log(a);
    14. console.log(a+b);
    15. }
    16. go(10)

    使用arguments对象模拟重载

    1. 伪数组
    2. 1,具有数组的length属性
    3. 2,按照索引的方式进行存储的
    4. 3,它没有真正数组的一些方法 pop() push()等等
    1. <script>
    2. function getmax(){
    3. var max = arguments[0];
    4. for(var i=1;i<arguments.length;i++){
    5. if(arguments[i]>max){
    6. max = arguments[i];
    7. }
    8. }
    9. return max;
    10. }
    11. console.log(getmax(1,2,3));
    12. console.log(getmax(100,24,31,8,90));
    13. console.log(getmax(1,2,33,520,24,520.1));
    14. </script>
    // js 传递传不定参,函数使用arguments对象来管理函数内部的参数            
    function go(){
                if(arguments.length==1){
                    console.log(arguments[0]);
                }else if(arguments.length==2){
                    console.log(arguments[0]+arguments[1]);
                }
            }
            go(1)
            go(10,20)