Created
December 26, 2019 07:40
-
-
Save zba/fedbba3500a76fd8a7bbd0df922dad4c to your computer and use it in GitHub Desktop.
This file contains 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
// made to be able to wrap window, in case when Localstorage is unavailable | |
function copy(object) { | |
try { | |
return Object.assign({}, object) | |
} catch(e) { | |
const result = {}; | |
Object.keys(object).forEach(key=> { | |
let value; | |
try { | |
value = object[key]; | |
}catch(e) { | |
value = null; | |
} | |
if (typeof value !== 'object' || value === null || value===object) { | |
result[key] = value | |
} else { | |
result[key]=copy(value) | |
} | |
}); | |
return result; | |
} | |
} | |
// example | |
// copy(window) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment