日期:2014-05-16  浏览次数:20391 次

递归
JScript code

function factorial(num){
    if (num < = 1){
        return 1;
    }else{
        return num * argumets.callee(num-1);
    }
}
var anotherFactorial = factorial;
factorial = null;
alert(anotherFactorial(4));
为何运行时没结果



------解决方案--------------------
JScript code

    <script type="text/javascript">
        function factorial(num) {
            if (num <= 1) {
                return 1;
            } else {
                return num * arguments.callee(num - 1);//这里有拼写错误arguments
            }
        }
        var anotherFactorial = factorial;
        factorial = null;
        alert(anotherFactorial(4));
    </script>

------解决方案--------------------
JScript code
function factorial(num){
    if (num <= 1){//前面是<=,不能写成< =
        return 1;
    }else{
        return num * arguments.callee(num-1);//写错了arguments,你少写了个n
    }
}

------解决方案--------------------
探讨
if (num < = 1) // 应该是if (num <= 1)
说实在我有点看不懂你的代码为什么那样写。也不知道你是不是想实现1x2x3x....xN的结果。如果是的话应该写: