Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created February 2, 2020 18:42
Show Gist options
  • Save jsmanifest/f7e137a660307605261e17df0296cc5d to your computer and use it in GitHub Desktop.
Save jsmanifest/f7e137a660307605261e17df0296cc5d to your computer and use it in GitHub Desktop.
function createMyHigherOrderFunction(options) {
const state = { ...options } // Our local state object
return function(...args) {
return function(callback) {
return callback(state, ...args)
}
}
}
const prepare = createMyHigherOrderFunction({
name: 'bobby',
favoriteFood: 'steak',
})
const prepareWithArgs = prepare({ country: 'United States' })
const finalize = prepareWithArgs((state, options) => ({ ...state, ...options }))
console.log(finalize)
/*
result: {
country: "United States",
favoriteFood: "steak",
name: "bobby"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment