I have a set of POST endpoints where I need to send a collection of static parameters plus a few dynamic parameters specific to the request.
For every request, I am doing the following:
var staticParams = {...}, // some arbitrarily large object
localParams = {...},
formData = new FormData();
Object.keys(staticParams).forEach(function(key) {
formData.append(key, staticParams[key]);
});
Object.keys(localData).forEach(function(key) {
formData.append(key, localParams[key]);
});
It's not a huge tax, but it seems silly to repeat the first enumeration for every request. How can I clone and extend my FormData
object so that I don't have to build the whole thing every time?
FWIW, I know how to clone Objects; I believe FormData
is unique in that the key/value pairs are not simply keys on the Object, so I am unclear on the correct way to clone it.