javascript 实现的阶乘函数

| |
[不指定 2009/10/09 14:05 | by phpor ]
// Y 函数实现的太绕了,太难以理解了, 无语。

function 
factorial(proc) {
    return function (
n) {
        return (
<= 1) ? proc(n-1);
    }
}

function 
Y(outer) {
    function 
inner(proc) {
        function 
apply(arg) {
            return 
proc(proc)(arg);
        }       
        return 
outer(apply);
    }
    return 
inner(inner);
}

alert("5! is " Y(factorial)(5));
Java » JavaScript | 评论(0) | 引用(0) | 阅读(103)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]