Created
April 30, 2019 19:13
-
-
Save splincode/cfa70136c7005c84f21157a18adba79f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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