Does javascript's curry function use the closing principle?

It would be very helpful if someone would explain the work of curry. I read many examples, but could not understand it properly. This is somehow related to the closure.

+4
source share
1 answer

Currying is simply a method that can use any function of the language (for example, closure) to achieve the desired result, but it is not determined which language function to use. Since shutters are not required for this currying (but in most cases shutters will be used)

Here is a small example of using currying, with and without using closure.

:

function addition(x,y) {
  if (typeof y === "undefined" ) {
    return function (y) {
      return x + y;
    }
  }
  return x + y;
}

var additionRemaining = addition(3); // Currying
additionRemaining(5);//add 5 to 3

new Function ( ):

function addition(x,y) {
  if (typeof y === "undefined" ) {
    return new Function('y','return '+x+' + y;');
  }
  return x + y;
}

var additionRemaining = addition(3); // Currying
additionRemaining(5);//add 5 to 3
+5

All Articles