Currying

来源:互联网 发布:c语言的应用范围 编辑:程序博客网 时间:2024/05/21 07:00

Every function receives one parameter and then returns a new function.

function a(x){    return function b(y)    {        return function c(z)        {            return x+y+z;        }    }}a(1)(2)(3);    //6

When the function returned itself,it is not Currying.

<html><body><p id="demo"></p></body><script>    var obj = document.getElementById("demo");    var appendFun = function(str){        obj.innerHTML+=str;        return appendFun;    }    appendFun("Hello")(" javascript")(" heihei")(" heihei.");    //Hello javascript heihei heihei.</script></html>
0 0
原创粉丝点击