js中重载问题

在js中是没有重载的  但是  Arguments对象(可以实现模拟重载的效果)

利用arguments对象的length属性,可以获取函数接收的参数的个数

 例如:

function add(){
	if(arguments.length == 2){
		return arguments[0] + arguments[1];		
	}else if(arguments.length == 3){
		return arguments[0] + arguments[1] + arguments[2];
	}
}	

add(2,4);    //output      6
add(2,4,5);    //output     11
原文地址:https://www.cnblogs.com/taochengyong/p/8316862.html