Skip to content

Instantly share code, notes, and snippets.

@ferfabricio
Created March 12, 2019 02:04
Show Gist options
  • Save ferfabricio/05a0964d25a616b9c93f6de83aaa8f47 to your computer and use it in GitHub Desktop.
Save ferfabricio/05a0964d25a616b9c93f6de83aaa8f47 to your computer and use it in GitHub Desktop.
Spread operator
function createRequestOptions(options) {
const defaultParameters = {
url: 'devparana.org',
method: 'GET',
secure: true
}
return {
...defaultParameters,
...options
}
}
console.log(createRequestOptions({ url: 'portalmaringa.com' }))
// Resultado
// { url: 'portalmaringa.com', method: 'GET', secure: true }
console.log(createRequestOptions({ method: 'POST' }))
// Resultado
// { url: 'devparana.org', method: 'POST', secure: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment