Skip to content

Instantly share code, notes, and snippets.

@Equinox-
Last active Dec 14, 2015
Embed
What would you like to do?
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