实参和形参

<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>
原文地址:https://www.cnblogs.com/chengpeng/p/2133697.html