Created
February 2, 2020 18:42
-
-
Save jsmanifest/f7e137a660307605261e17df0296cc5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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