fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * 深度复制
 * @param {*} from 源对象
 * @param {*} to 目标对象
 */
export function objectCopy (from, to) {
  if (from === null) { return null }
  if (to) {
    for (const i in to) {
      if (from[i] || typeof from[i] !== 'undefined') {
        to[i] = typeof from[i] === 'object' ? objectCopy(from[i]) : from[i]
      }
    }
  } else {
    to = from instanceof Array ? [] : {}
    for (const i in from) {
      to[i] = typeof from[i] === 'object' ? objectCopy(from[i]) : from[i]
    }
  }
  return to
}