Skip to content

Instantly share code, notes, and snippets.

@splincode
Created April 30, 2019 19:13
Show Gist options
  • Save splincode/cfa70136c7005c84f21157a18adba79f to your computer and use it in GitHub Desktop.
Save splincode/cfa70136c7005c84f21157a18adba79f to your computer and use it in GitHub Desktop.
function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj)); // serialize -> deserialize -> unique clone
}
const original = {
a: new Date(),
b: NaN,
c: new Function(),
d: undefined,
e: function(){},
f: Number,
g: false,
h: Infinity,
i: window,
}
const copy = deepCopy(original); // Runtime error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment