deepClone.js 338 B

1234567891011121314
  1. //深拷贝
  2. export function deepClone(source) {
  3. if (source === null || typeof source !== 'object') {
  4. return source
  5. }
  6. const target = Array.isArray(source) ? [] : {}
  7. for (const key in source) {
  8. if (Object.prototype.hasOwnProperty.call(source, key)) {
  9. target[key] = deepClone(source[key])
  10. }
  11. }
  12. return target
  13. }