重载:根据传入的参数不一样,动态决定调用哪一种方法
原因:js不支持重载,重复声明,就被覆盖掉了
可以使用arguments对象模拟重载 通过下标去读
<script>function go(a,b){console.log(a+b)}function go(a){console.log(a);}function show(){if(arguments.length==2){console.log(arguments[0]+arguments[1])}else if(arguments.length==1){console.log(arguments[0])}}show(20) //20show(20,30) //50 *//*eg:var a=20;var a=30; //此时a的值为30 */</script>
