改变了原对象
obj1 = {a:1,b:{b1:1}} obj2 = Object.assign({},obj1) obj2.b.b1=2console.log(obj1.b.b1)// 2
obj1 = {a:1,b:{b1:1}} obj2 = Object.assign({},obj1,{}) obj2.b.b1=2console.log(obj1.b.b1)// 2
未改变原对象
obj1 = {a:1,b:{b1:1}} obj2 = {a:2,b:{b1:2}} obj3 = Object.assign({},obj1,obj2) obj3.b.b1=8console.log(obj1.b.b1)// 1
慕尼黑5688855
相关分类