Here is my function which I am using to override the clone
property of an object to create a new copy of the object not only the reference.
Object.prototype.clone = function () {
var 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 have also added few properties to the window object
.
Edit
Actually I am using seeveral libraries in my code. When I run this method without these libraries, it works fine. But with these libraries it gives this error. It is possible they have provided their own implementation of clone.
Now when I call this method I get the Maximum call stack size exceeded
.
Any Help? Thank you