-
-
Save getify/800d2333440efe0ffa0b190ef21d69ae to your computer and use it in GitHub Desktop.
merging defaults/settings objects with destructuring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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