Curling :
curling is process of converting a function into n functions based on passed n parameters and each function takes single parameter and return the next function .
Curling function is a function but n arguments, and those arguments are split into n functions, each of which takes a single argument.
Example: closures
syntax:
const curling=()=>{
return ()=> {
return ()=> {
return ()=> {
return ()=> { }
}
}
}
}
Normal function :
function test (num, num2, num3){
return num+ num2 + num3;
}
//Above function is converted to curling :
function test(num){
return function(num2){
return function (num3){
return num+ num2 + num3;
}
}
}
console.log(test(2)) // remaining block will be returned..
console.log(test(2)(2)(4))
Example _2
function test(num){
return function(num2){
return num* num1;
}
}
var mainFunctioncalling = vyshu(20);
console.log(mainFunctioncalling(10)); // second variable value passed.
//Or
console.log(vyshu(10)(6));
Through Bind() method :
var multiply = (x,y) =>{
return x*y;
}
var multiplyByFive = multiply.bind(this,5);
multiplyByFive(2)
Short example :
const add = x => y=>x+y;