js 实现Object的clone方法(深度克隆)

function deepClone(origin, target){
    var target = target || {},
    toStr = Object.prototype.toString,
    arrStr = "[object Array]";
    for(var prop in origin){
        if(origin.hasOwnProperty(prop)){
            if(origin[prop] !== "null" && typeof(origin[prop]) == "object"{
            target[prop] = (toStr.call(origin[prop]) == arrStr) ? [] : {};                    
                deepClone(origin[prop],target[prop]);
          }else{
              target[prop] = origin[prop]
          }
        }
    }
}        

 

posted @ 2019-05-31 11:39  Echo的前端空间  阅读(3004)  评论(0编辑  收藏  举报