-1

Theortically I know what currying is.

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

Rohit Goyal
  • 212
  • 1
  • 2
  • 8

2 Answers2

2

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.

jcollado
  • 39,419
  • 8
  • 102
  • 133
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.

Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135