我不是很肯定的問題標題, 這裏的情況,請參見下面的示例代碼JavaScript對象的屬性值衝突
// original data
a = [
{x : 1},
{x : 2},
{x : 3}
]
// assign to a variable
b = a[0]
// do some change
b.x = 5
alert(a[0].x)
// i thought it would still be 1 but it is 5, why???
*編輯
謝謝琥珀和安德烈
我認爲我只寫一個函數來循環通過對象屬性來複制到一個新的對象
再次感謝您的幫助:)
你應該看看http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object關於如何做到這一點的一些建議。 – 2010-07-15 08:13:17