0
아래 코드를 사용하고 있습니다.하지만이 기능은 좋지만 JQuery를 동시에 사용하려고하면 아래 오류가 발생합니다. 게시물 및 나는 문제가 아니 생각 가능한 hasOwnProperty()를 확인하지 않고 Object.prototype을 확장 할 수 있다고 생각하지만, 어떻게 해결할 수 있을지 모르겠 누군가가 나에게 손을 줄 수 있습니까?잡히지 않은 TypeError : 객체에 'exec'메서드가 없습니다.
코드 :
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;
};
오류 :
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'
을 jsFiddle에 당신은 또한 오류가 발생했습니다? – Dvir
'Object.prototype'에 메서드를 두지 않을 것을 제안합니다. 대신에 그것을 상속받지 않도록'Object'에 메소드로 넣고 첫 번째 인자로 복제 할 객체를 전달하십시오. 'Object.clone (foo)' – user2736012
@Dvir : jsFiddle이 무엇을해야합니까? – user2736012