loading...

re: What's the best way to deeply clone an object in JavaScript? VIEW POST

FULL DISCUSSION
 

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
 

This is awesome! Thanks for also adding the test cases

code of conduct - report abuse