深复制

// 深复制
let deepCopy = (data) => {
  let result;
  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;
};

猜你喜欢

转载自www.cnblogs.com/ysk123/p/9480539.html