重载:就是根据参数的不同,动态决定调用哪个方法
js中没有重载的概念,因为重复声明,下面的会覆盖上面的
//js中没有重载的概念,因为重复声明,下面的会覆盖上面的function go(a){console.log(a);}function go(a,b){console.log(a+b);}
使用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)
