var request = {
headers: {
"CONTENT-TYPE": "application/json",
"accept": "application/json"
}
};
目的是获取普通对象,但使用“规范化”键。如何将keys
andvals
与 Underscore 结合使用?
var normalize = function(h) { return h.toUpperCase(); },
keys = _.map(_.keys(request.headers), normalize),
vals = _.values(request.headers);
// Now combine (no obvious looping) keys and vals to obtain
// {
// headers: {
// "CONTENT-TYPE": "application/json",
// "ACCEPT": "application/json"
// }
// }