我有一个 JavaScript 对象:
var credentials =
{
uid: response.authResponse.userID,
accessToken: response.authResponse.accessToken
};
如何添加此对象name: response.something
?
答案 0 :(得分:3)
JavaScript对象是动态的。这意味着您可以随时添加任何属性,只需执行以下操作:
credentials.name = response.something;
或等效地:
credentials['name'] = response.something;
Object.defineProperty( credentials, "name", {
value: response.something,
writable: true,
enumerable: true,
configurable: true
});