深克隆

function cloneObj (obj) {
  var str, newobj = obj.constructor === Array ? [] : {};
  if (typeof (obj) !== 'object') {
    return;
  } else {
    for (var i in obj) {
      newobj[i] = typeof (obj[i]) === 'object' && obj[i] ? this.cloneObj(obj[i]) : obj[i];
    }
  }
  return newobj;
};

posted @ 2020-04-22 10:20  Jay_Lo  阅读(122)  评论(0编辑  收藏  举报