对象克隆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半段

posted @ 2016-04-28 10:07  挥刀  阅读(125)  评论(0编辑  收藏  举报