用JSON.stringify去實現深拷貝的弊端


無法處理function啦還有RegExp啦,還有無法處理循環引用對象(這個我還沒有test)

就前兩點的話

var a={
    a:1,
    b:new RegExp('test'),
    c:function(){}
}

然后var b=JSON.parse(JSON.stringify(a))

輸出b的話

{
a: 1
b: {}
}

就這樣啦

c:function都沒有復制過來,RegExp對象沒有處理

 

 

還有什么的話歡迎補充啦

------------------------------

我暈 好像我看stackoverflow上面這個弊端還蠻多的

 you do not use Dates, functions, undefinedInfinity, RegExps, Maps, Sets, Blobs, FileLists, ImageDatas, sparse Arrays, Typed Arrays or other complex types within your object, a very simple one liner to deep clone an object is:

這么多都不能處理呢


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM