zhoushihao
2024-12-24 b5e913e90d7cd40a329663276954cd4d397afef5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//深度拷贝,使数据进行绑定显示
export default  function deepClone(obj){
    // 对常见的“非”值,直接返回原来值
    if([null, undefined, NaN, false].includes(obj)) return obj;
    if(typeof obj !== "object" && typeof obj !== 'function') {
        //原始类型直接返回
        return obj;
    }
    var o = Array.isArray(obj) ? [] : {};
    for(let i in obj) {
        if(obj.hasOwnProperty(i)){
            o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i];
        }
    }
    return o;
}