Skip to content

Instantly share code, notes, and snippets.

@getify getify/1.js
Created Jun 7, 2019

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