实参和形参
2011-08-10 15:03 鹏雕 阅读(218) 评论(0) 编辑 收藏 举报<script language="javascript" type="text/javascript">
function check(args)
{
var actual=args.length;//实际传入参数的个数
var expected = args.callee.length; //形参个数Function.length
var isPass = false;
try
{
if (actual != expected) {
throw new Error("参数个数不匹配");
}
else {
isPass = true;
}
}
catch(exception)
{
return exception.message;
}
return isPass;
}
function test(x, y, z) {
var temp = check(arguments)
if (temp==true) {
return x + y + z;
}
else {
return temp;
}
}
document.write(test(1,2,3),"<br />");//output 6
document.write(test(1), "<br />"); //output 参数个数不匹配
document.write(test.prototype.toLocaleString()); //output [object Object]
document.write(check.prototype.toLocaleString());//output [object Object]
</script>