Created
February 13, 2014 04:11
-
-
Save basecss/8969604 to your computer and use it in GitHub Desktop.
deep clone 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
function deepClone(target) { | |
if(typeof target !== 'object') { | |
return target; | |
} | |
if(target.constructor === RegExp) { | |
return target; | |
} | |
var result = new target.constructor(); | |
for(var key in target) { | |
if(!target.hasOwnProperty(key)) { | |
continue; | |
} | |
result[key] = deepClone(target[key]); | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment