Created
May 21, 2021 14:20
-
-
Save ocommaj/bcc5621abfc55d4b91321a11d1e5c550 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
const init = function(type) { | |
let id = 0; | |
return (name, props=null) => { | |
id +=1; | |
return { | |
id, | |
type, | |
name, | |
...props | |
} | |
} | |
} | |
const createUser = init('user') | |
const createBook = init('book') | |
const dave = createUser('Dave') | |
const book = createBook('Moby Dick', { author: createUser('Herman') }) | |
console.dir(dave) | |
console.dir(book) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment