js 对象的深拷贝
function deepCopy(obj) { var result = Array.isArray(obj) ? [] : {}; for (var key in obj) { if (obj.hasOwnProperty(key)) { if (typeof obj[key] === 'object') { result[key] = deepCopy(obj[key]); // 递归复制 } else { result[key] = obj[key]; } } } return result; } var obj = { name:111 } var obj2 = deepCopy(obj) obj2.name = 333 console.log(obj2)