function deepClone (obj) { if (obj === null) { // 如果是null则直接返回 return obj; } let copy = Array.isArray(obj) ? [] : {}; for (let key in obj) { if (obj.hasOwnProperty(key)) { if (typeof obj[key] === 'object') { copy[key] = deepClone(obj[key]); } else { copy[key] = obj[key]; } } } console.log(copy); return copy; } let a = { name: '小明', age: 23, children: [1, { aa: 1 }, 2, 3], fn: function (v) { return v; } }; let b = deepClone(a); console.log('b', b);