Skip to content

Instantly share code, notes, and snippets.

@idan idan/pattern.es6
Created Aug 3, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.