1. function deepClone(obj = {}) {
    2. // 如果是不需要克隆的类型直接返回
    3. if(typeof obj !== 'object' || obj === null) {
    4. return obj
    5. }
    6. // 根据是数组or对象初始化结果值
    7. let result
    8. if(obj instanceof Array) {
    9. result = []
    10. } else {
    11. result = {}
    12. }
    13. // 递归拷贝
    14. for(key of obj) {
    15. result[key] = deepClone(obj[key])
    16. }
    17. return result
    18. }