例如,这样的事情:btn.{ innerText = "hello", style.{ fontSize = "24px", outline = "none" }}代替:btn.innerText = "hello";btn.style.fontSize = "24px";btn.style.outline = "none";先谢谢您的帮助。
4 回答
慕容3067478
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
慕标5832272
TA贡献1966条经验 获得超4个赞
是的,当您将对象分配给变量时,您可以执行以下操作:
const obj = {
name: 'user54321',
age: 30,
...
};
慕少森
TA贡献2019条经验 获得超9个赞
const btn = {
innerText: "hello",
style: {
fontSize: "24px",
outline: "none"
}
}
添加回答
举报
0/150
提交
取消