4 回答

TA貢獻1773條經驗 獲得超3個贊
Object.assign正是您所需要的:
// declare obj with some props
const btn = {
? innerText: "initial"
};
// see what we have
console.log(JSON.stringify(btn))
// assign (and re-assign) some props
Object.assign(btn, {
? innerText: "hello",
? style: {
? ? fontSize: "24px",
? ? outline: "none"
? }
})
// see what changed
console.log(JSON.stringify(btn))

TA貢獻1806條經驗 獲得超8個贊
您可以使用文字對象初始值設定項:
let a = 1, b=2, c=3
const newObj = {a,b,c};
console.log(newObj.a);
// expected output: 1

TA貢獻1966條經驗 獲得超4個贊
是的,當您將對象分配給變量時,您可以執行以下操作:
const obj = {
name: 'user54321',
age: 30,
...
};

TA貢獻2019條經驗 獲得超9個贊
const btn = {
innerText: "hello",
style: {
fontSize: "24px",
outline: "none"
}
}
添加回答
舉報