Im working on a js game, and trying to clone an object, but I keep having this error :
this[i].clone is not a function
this is my code :
Object.prototype.clone = function() {
var i, newObj = (this instanceof Array) ? [] : {};
for (i in this) {
if (i === 'clone') {
continue;
}
if (this[i] && typeof this[i] === "object") {
newObj[i] = this[i].clone();
} else {
newObj[i] = this[i];
}
}
return newObj;
};
I tried to remplace 'clone' with this solution :
JSON.parse(JSON.stringify(object))
it didn't work. any help please ?