2012-03-07 54 views
0

可能重複:
What is the most efficient way to clone a JavaScript object?
Copying an Object in Javascript如何獲取一個新的對象引用

如果我有這樣的

var a = {}; 
a.test1 = 1; 
a.test2 = 2; 

,然後我做

var b = a; 

b.test1 = 5; 

我不想讓a.test1也改變。我如何獲得新的參考或對象?

+0

http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/ – androidavid 2012-03-07 23:48:21

+1

http://stackoverflow.com/questions/122102/what-is-the-most-efficient-克隆的方式來克隆一個JavaScript對象 – Ryan 2012-03-07 23:48:37

+0

http://stackoverflow.com/questions/728360/copying-an-object-in-javascript – Ryan 2012-03-07 23:48:47

回答

0

您應該自己創建對象並將原始對象的所有屬性複製到它。

相關問題