Created
January 8, 2020 18:32
-
-
Save BigRaj/a651ac57808456c1c93e2bf67aa26b50 to your computer and use it in GitHub Desktop.
Object Clone Prototype
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
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