Skip to content

Instantly share code, notes, and snippets.

@ilagnev
Created January 20, 2019 06:24
Show Gist options
  • Select an option

  • Save ilagnev/4da26f95622d066e6a567c89096815e3 to your computer and use it in GitHub Desktop.

Select an option

Save ilagnev/4da26f95622d066e6a567c89096815e3 to your computer and use it in GitHub Desktop.
function to get objects with default values in es2015 style
const createUser = ({
userName = 'Anonymous',
avatar = 'anon.png'
} = {}) => ({
userName,
avatar
})
// {userName: 'echo', avatar: 'anon.png'}
createUser({ userName: 'echo' })
// {userName: 'Anonymous', avatar: 'anon.png'}
createUser()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment