Skip to content

Instantly share code, notes, and snippets.

@Equinox-
Last active December 14, 2015 18:09
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 Equinox-/5127232 to your computer and use it in GitHub Desktop.
Save Equinox-/5127232 to your computer and use it in GitHub Desktop.
Object cloning in javascript
Object.prototype.clone = function () {
var obj = {};
for (key in this) {
obj[key] = this[key];
}
return obj;
}
Object.prototype.deepClone = function () {
var obj = {};
for (key in this) {
if (typeof(this[key]) == "object") {
obj[key] = this[key].deepClone();
}else{
obj[key] = this[key];
}
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment