Skip to content

Instantly share code, notes, and snippets.

@jyotiarora2610
Created July 2, 2019 01:25
Show Gist options
  • Save jyotiarora2610/1aafe59d109ab4fb75b3cebc0cf2d0fb to your computer and use it in GitHub Desktop.
Save jyotiarora2610/1aafe59d109ab4fb75b3cebc0cf2d0fb to your computer and use it in GitHub Desktop.
// using bind
var sum = function(x, y) {
return x+y
}
var sumCall = sum.bind(this);
sumCall(3, 2);
var sumCall = sum.bind(this, 3);
sumCall(2);
// using closure
var sum1 = function(x) {
return function(y) {
return x+y;
}
}
var sumCall1 = sum1(3);
sumCall1(2);
// nth currying
var sumN = function(a) {
return function(b) {
return b ? sumN(a+b) : a;
}
}
sumN(1)(2)(3)(4)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment