Created
October 15, 2020 06:35
-
-
Save NoriSte/5d9ca4abdbffb7bc194be159898a7314 to your computer and use it in GitHub Desktop.
Re-implementing Recoil APIs / article gists
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
// @see https://github.com/NoriSte/recoil-apis | |
// core function, it requires the id | |
function logId(id: string) { | |
console.log(id); | |
} | |
// create a new function that accesses the id thanks to its closure | |
function createLogid(id: string) { | |
// pubklic functions, it doesn't require the id | |
return function () { | |
logId(id); | |
}; | |
} | |
// you can log the iod only if you know it | |
logId("1"); | |
// higher-order function creation | |
const logIdWithoutKnowingIt = createLogid("1"); | |
// you can log the id without knowing it | |
logIdWithoutKnowingIt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment