What is the use of currying in javascript?

时间:2015-11-12 11:51:42

标签: javascript function currying

Theortically I know what currying is.

Can anyone tell me the practical use of currying in javascript?

2 个答案:

答案 0 :(得分:1)

Exactly the same as in every other language, e.g. easy partial application:

function curriedAdd(a) {
    return function(b) {
        return a + b;
    }
}

var xs = [1, 2, 3].map(curriedAdd(2));

Compare this to an uncurried approach:

function add(a,b) {
    return a + b;
}

var xs = [1,2,3].map(add.bind(null, 2));

There's nothing super special about JS in this regard.

答案 1 :(得分:1)

In my opinion what make currying interesting is that it makes easier to compose functions using a pointfree programming style.

You can find more information in this book chapter.

相关问题