在JavaScript中深度克隆對象的最有效方法是什麼? - What is the most efficient way to deep clone an object in JavaScript?

問題:

What is the most efficient way to clone a JavaScript object? 克隆JavaScript對象的最有效方法是什麼? I've seen obj = eval(uneval(o)); 我見過obj = eval(uneval(o)); being used, but that's non-standard and only supported by Firefox . 正在使用,但這是非標準的,僅受Firefox支持

I've done things like obj = JSON.parse(JSON.stringify(o)); 我已經完成了obj = JSON.parse(JSON.stringify(o)); but question the efficiency. 但質疑效率。

I've also seen recursive copying functions with various flaws. 我還看到了具備各類缺陷的遞歸複製功能。
I'm surprised no canonical solution exists. 我很驚訝沒有規範的解決方案存在。 spa


解決方案:

參考一: https://stackoom.com/question/VlO/在JavaScript中深度克隆對象的最有效方法是什麼
參考二: https://oldbug.net/q/VlO/What-is-the-most-efficient-way-to-deep-clone-an-object-in-JavaScript
相關文章
相關標籤/搜索