let obj={ name:"吴小明", age:24, love:{ pingpang:true } } let obj1=obj; obj.name="孙艺珍"; obj.love.pingpang=false; console.log(obj) console.log(obj1)
输出结果为:
{name: "孙艺珍", age: 24,love: {pingpang: false}}
aa.html:20 {name: "孙艺珍", age: 24,love: {pingpang: false}}
let obj={ name:"吴小明", age:24, love:{ pingpang:true } } let obj1={...obj}; obj.name="孙艺珍"; obj.love.pingpang=false; console.log(obj) console.log(obj1)
输出结果为:
{name: "孙艺珍", age: 24,love: {pingpang: false}}
aa.html:20 {name: "吴小明", age: 24,love: {pingpang: false}}
所以,let obj1={...obj};的意思是如果obj只有一层数据结构,这样复制的对象没有引用关系。