Skip to content

Instantly share code, notes, and snippets.

@basecss
Created February 13, 2014 04:11
Show Gist options
  • Save basecss/8969604 to your computer and use it in GitHub Desktop.
Save basecss/8969604 to your computer and use it in GitHub Desktop.
deep clone object
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