I'm using the code below and It's working good, but when I try to use JQuery at the same time, then I'm getting the below error, I was reading some posts and I think the problem is that no is possible extend the Object.prototype without checking hasOwnProperty(), but I don't know how to solve that, can someone give me a hand?
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;
};
Error:
Uncaught TypeError: Object 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;
} has no method 'exec'