Skip to content

Instantly share code, notes, and snippets.

@BigRaj
Created January 8, 2020 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigRaj/a651ac57808456c1c93e2bf67aa26b50 to your computer and use it in GitHub Desktop.
Save BigRaj/a651ac57808456c1c93e2bf67aa26b50 to your computer and use it in GitHub Desktop.
Object Clone Prototype
Object.prototype.clone = function(){
var obj = (this instanceof Date) ? new Date(this) : (this instanceof Array) ? [] : {};
if(obj instanceof Date)
return obj;
for(i in this){
if(i == 'clone')
continue;
(this[i] && typeof this[i] == 'object') ? obj[i] = this[i].clone() : obj[i] = this[i];
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment