实现深拷贝

最简单常用的:JSON.parse(JSON.stringify(obj))

简洁版:

    function deepCopy(obj) {
         let result;
         if(typeof obj === 'object' && obj!==null){
             result = obj.constructor === Array ? [] : {};
             for(let i in obj){
                 result[i] = typeof obj[i]==='object'?deepCopy(obj[i]):obj[i]
             }
         } else{
             result = obj
         }
         return result
     }
原文地址:https://www.cnblogs.com/yourName/p/12395406.html