function Deepclone (obj) {var _tostring = Object.prototype.toString; null, undefined, non-object, function if (!obj | | typeof obj!== ' object ') {return obj; }//DOM Node if (obj.nodetype && ' CloneNode ' in obj) {return Obj.clonenode (true); }//Date if (_tostring.call (obj) = = = ' [object Date] ') {return new Date (Obj.gettime ()); }//RegExp if (_tostring.call (obj) = = = ' [object RegExp] ') {var flags = []; if (Obj.global) {Flags.push (' G ');} if (obj.multiline) {Flags.push (' m ');} if (obj.ignorecase) {Flags.push (' I ');} return new RegExp (Obj.source, Flags.join (")); } var result = Array.isarray (obj)? []: Obj.constructor? New Obj.constructor (): {}; for (var key in obj) {Result[key] = Deepclone (Obj[key]); } return result; function A () {this.a = A;} var a = {name: ' Qiu ', birth:new Date (), Pattern:/qiu/gim, Container:document.body,Hobbys: [' book ', New Date (),/aaa/gim, 111]};var C = new A (), var B = Deepclone (c); Console.log (c.a = = = B.A); Console.log (c, b);
Writing JavaScript deep-clone functions Deepclone