美文网首页
js对象深拷贝(简单实现)

js对象深拷贝(简单实现)

作者: 大福爸爸_ | 来源:发表于2020-04-01 15:10 被阅读0次
function deep(data) {
    if(!data || typeof data != Object) {
        return data;
    }
    let result = data.constructor;
    let strName = Object.prototype.toString.call(data);
        for(let key in data) {
            if(data.hasOwnPorperty(key))
           result[key] = deep(data[key]);
        }
    return result;

}

相关文章

网友评论

      本文标题:js对象深拷贝(简单实现)

      本文链接:https://www.haomeiwen.com/subject/syhauhtx.html