DEV Community

Discussion on: What's the best way to deeply clone an object in JavaScript?

Collapse
 
pengeszikra profile image
Peter Vivo • Edited

Are you means?

const base = {
  a: {
   b: [1,2,4],
   c: 'call me c'
  }, 
  d: p => p * 2, 
  get orig(){ return base}
};

const result = deepCopy(base);

test cases (mandatory true)

  result.a !== test.a
  result.a.b !== test.a.b
  result.a.c === test.a.c
  result.d !== test.d
  result.d(42) === test.d(42)
  test.orig === test
  result.orig === test
  result.orig !== result
Collapse
 
jasterix profile image
Jasterix

This is awesome! Thanks for also adding the test cases