arguments[1],arguments[2],arguments[3]));
//document.write(Array.apply(this,arguments));
}
ff(1,2,3,4);
、 一个使用 C 对象模拟函数重载的例子
function Point()
{
if(arguments.length==0)
{
this.x=0;
this.y=0;
}
else if(arguments.length==1)
{
var p=arguments[0];
if(p instanceof Point)
{
this.x=p.x;
this.y=p.y;
}
else if(typeof(p)=="number" || p instanceof Number)
{
this.x=Number(p);
this.y=0;
}
else
throw new TypeError("参数类型错误!");
}
else if(arguments.length==2)
{
var x=arguments[0];
var y=arguments[1];
if((typeof(x)=="number" || x instanceof Number)&&
(typeof(y)=="number" || y instanceof Number))
{
this.x=Number(x);
this.y=Number(y);
//this.x=x;
//this.y=y;
}
else
throw new TypeError("参数类型错误!");
}
else