首页 > 代码库 > 避免原型链上面的对象共享

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

 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>

 

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