对象数组 深拷贝

  1. function clone(obj) {
    var o;
    if (typeof obj == "object") {
    if (obj === null) {
    o = null;
    } else {
    if (obj instanceof Array) {
    o = [];
    for (var i = 0, len = obj.length; i < len; i++) {
    o.push(clone(obj[i]));
    }
    } else {
    o = {};
    for (var j in obj) {
    o[j] = clone(obj[j]);
    }
    }
    }
    } else {
    o = obj;
    }
    return o;
    }

posted @ 2018-03-20 10:55  miumiu316  阅读(135)  评论(0编辑  收藏  举报