Created
May 16, 2015 00:06
-
-
Save toejough/df94aee238586c283b6f to your computer and use it in GitHub Desktop.
clone javascript object
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
// clone a basic object (no functions or recursion) | |
// also handles 'undefined' and 'null' | |
function clone_obj(obj) { | |
if (obj === undefined || obj === null) { | |
return obj; | |
} | |
return JSON.parse(JSON.stringify(obj)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment