深复制

// 深复制
let deepCopy = (data) => {
  let result = Array.isArray(data)?[]:{};
  if (typeof data === 'object') {
    if (JSON) {
      result = JSON.parse(JSON.stringify(data));
    } else {
      for (let i in data) {
        result[i] = typeof data[i] === 'object' ? deepCopy(data[i]) : data[i];
      }
    }
  }
  return result;
};
posted @ 2018-08-15 11:43  诗和远方-ysk  阅读(125)  评论(0编辑  收藏  举报