Skip to content

Instantly share code, notes, and snippets.

@getify
Created June 7, 2019 21:04
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 getify/800d2333440efe0ffa0b190ef21d69ae to your computer and use it in GitHub Desktop.
Save getify/800d2333440efe0ffa0b190ef21d69ae to your computer and use it in GitHub Desktop.
merging defaults/settings objects with destructuring
ajax(
ajaxOptions({
url: "https://my.other.tld/api",
headers: {
"Cache-Control": "no-cache"
},
cb: resp => console.log(resp)
})
);
// *****************************
function ajaxOptions({
url = "https://some.tld",
method = "GET",
headers: {
"Content-Type": contentType = "text/plain",
...otherHeaders
} = {},
...otherSettings
} = {}) {
return {
url, method,
headers: { "Content-Type": contentType, ...otherHeaders },
...otherSettings
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment