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