Skip to content

Instantly share code, notes, and snippets.

@stephane777
Created November 12, 2019 22:22
Show Gist options
  • Select an option

  • Save stephane777/c5e2af774acc026a986babb8a8fdc7fb to your computer and use it in GitHub Desktop.

Select an option

Save stephane777/c5e2af774acc026a986babb8a8fdc7fb to your computer and use it in GitHub Desktop.
function add (x, y) {
return x + y
}
function makeAdder (x, addReference) {
return function (y) {
return addReference(x, y)
}
}
const addFive = makeAdder(5, add)
const addTen = makeAdder(10, add)
const addTwenty = makeAdder(20, add)
addFive(10) // 15
addTen(10) // 20
addTwenty(10) // 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment