Created
March 5, 2014 16:51
-
-
Save shinout/9371224 to your computer and use it in GitHub Desktop.
minimal deep copy in JavaScript
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(val) { | |
if (Array.isArray(val)) return val.map(deepCopy); | |
if (typeof val != "object" || val === null || val === undefined) return val; | |
var ret = {}; | |
for (var attr in val) if (val.hasOwnProperty(attr)) ret[attr] = deepCopy(val[attr]); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment