当我从现有对象创建一个新对象,然后附加一个新属性时,为什么它会更新较早的属性?
他们的解决方案是否不需要过多更改我的代码?
var data = [
  {
    "id" : 1,
    "name" : "carrot",
    "price" : 0.10,
    "stock" : 12,
    "bgLocation" : "-1px -54px"
  },
  {
    "id" : 2,
    "name" : "fennel",
    "price" : 1.20,
    "stock" : 6,
    "bgLocation" : "-146px -52px"    
  }
]
var item = data[0];
item.added = 4;
//data[0] should not contain the added attribute.
$('body').append(JSON.stringify(data[0]));