避免原型链上面的对象共享

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8 <script>
 9     var a = {name: "m"};
10     var b = cloneObj(a);
11     function cloneObj(obj) {
12         var f = function () {};
13         f.prototype = obj;
14         return new f();
15     }
16     console.log(b.name);
17 </script>
18 </body>
19 </html>

 

posted @ 2016-11-25 10:41  晨落梦公子  阅读(665)  评论(0编辑  收藏  举报