对象克隆2

 1 <!doctype html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6 </head>
 7 <body>
 8 <script>
 9 var c = {
10     w:10
11 }
12 var t = [
13         1,2,3,4
14 ];
15     var a = {
16         q:c,
17         s:t,
18         x:90
19     }
20 
21     var bb = JSON.parse(JSON.stringify(a));
22     console.log(bb);
23     bb.s[0] = 1000;
24     console.log(a.s[0]);
25     console.log(bb.s[0]);
26 </script>
27 </body>
28 </html>

将对象先反序列化在序列化;必须确保是安全的json格式;

可以先做个if半段

坚持下去就能成功
原文地址:https://www.cnblogs.com/suoking/p/5441563.html