对象或数组 或数组对象的深拷贝

时间:2021-08-19 19:52:38

objDeepCopy: (source) => {
       var sourceCopy = source instanceof Array ? [] : {};
  for (var item in source) {
    if(typeof source[item] === 'object') {
      sourceCopy[item] = this.a.objDeepCopy ? this.a.objDeepCopy(source[item]) :(this.a.dp && this.a.dp.objDeepCopy)? this.a.dp.objDeepCopy(source[item]):
      this.b.objDeepCopy ? this.b.objDeepCopy(source[item]) :(this.b.dp && this.b.dp.objDeepCopy) ? this.b.dp.objDeepCopy(source[item]):source[item]
    }else{
      sourceCopy[item] = source[item]
    }
  }
  return sourceCopy
}