1 function deepCopy(obj) { 2 var result = Array.isArray(obj) ? [] : {}; 3 for (var key in obj) { 4 if (obj.hasOwnProperty(key)) { 5 if (typeof obj[key] === ‘object‘ && obj[key]!==null) { 6 result[key] = deepCopy(obj[key]); //递归复制 7 } else { 8 result[key] = obj[key]; 9 } 10 } 11 } 12 return result; 13 }
原文地址:https://www.cnblogs.com/ajaxkong/p/11692196.html
时间: 2024-11-04 00:37:11