1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title>对象深度克隆</title> 6 </head> 7 <body> 8 </body> 9 10 <script> 11 //对象深度克隆 12 function cloneObject(o) { 13 if (!o || ‘object‘ !== typeof o) { 14 return o; 15 } 16 var c = ‘function‘ === typeof o.pop ? [] : {}; 17 var p, v; 18 for (p in o) { 19 if (o.hasOwnProperty(p)) { 20 v = o[p]; 21 if (v && ‘object‘ === typeof v) { 22 c[p] = Ext.ux.clone(v); 23 } 24 else { 25 c[p] = v; 26 } 27 } 28 } 29 return c; 30 } 31 32 33 34 </script> 35 36 </html>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>对象深度克隆</title></head><body></body> <script> //对象深度克隆 function cloneObject(o) { if (!o || ‘object‘ !== typeof o) { return o; } var c = ‘function‘ === typeof o.pop ? [] : {}; var p, v; for (p in o) { if (o.hasOwnProperty(p)) { v = o[p]; if (v && ‘object‘ === typeof v) { c[p] = Ext.ux.clone(v); } else { c[p] = v; } } } return c; } </script> </html>
时间: 2025-01-10 16:11:52