Skip to content

Instantly share code, notes, and snippets.

@ocommaj
Created May 21, 2021 14:20
Show Gist options
  • Save ocommaj/bcc5621abfc55d4b91321a11d1e5c550 to your computer and use it in GitHub Desktop.
Save ocommaj/bcc5621abfc55d4b91321a11d1e5c550 to your computer and use it in GitHub Desktop.
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