Skip to content

Instantly share code, notes, and snippets.

@idan
Created August 3, 2015 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idan/3b9b422347afddc704bb to your computer and use it in GitHub Desktop.
Save idan/3b9b422347afddc704bb to your computer and use it in GitHub Desktop.
ES6 object argument pattern
function foo ({required, optional='default!'} = {}) {
console.debug(`${required}, ${optional}`)
}
foo({required: 'lala', optional: 'lolo'})
// -> "lala, lolo"
foo({required: 'lala', optional: null})
// -> "lala, null"
foo({required: 'lala' })
// -> "lala, default!"
foo({optional: 'pineapple' })
// -> "undefined, pineapple"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment