2013-07-23 53 views
0

時,排除一些JS類型,我得到:如何添加原型只要我下面的代碼添加到我的html頁面對象

Uncaught TypeError: Object function (constrname) { 
    if(this.constructor.name===constrname){ 
     return true; 
    } 

    return false; 
} has no method 'exec' 

這是導致錯誤的原型:

Object.prototype.isInstanceOf=function(constrname) { 
    if(this.constructor.name===constrname){ 
     return true; 
    } 

    return false; 
}; 

添加原型似乎打破了jQuery。

我可以排除某些類型時定義新的原型對象類型。例如,排除:jQuery的類型,...

我嘗試下面的代碼,但它是徒勞的:

Object.prototype.isInstanceOf=function(constrname) { 
     if(!(this instanceof jQuery)){ 
       //write here code 
     } 
} 
+3

不是,而是使其不可枚舉。更好的是,不要那樣做。 – SLaks

+0

你能詳細說明導致這個錯誤的條件嗎?我認爲jQuery寫得不夠好,不能打破這樣的事情。 – sabof

+0

@SLaks謝謝你的回答;但是,我應該讓誰不可枚舉,以及如何? –

回答

0

不,這是不可能的。原型繼承的整個要點是原型上的對象每後代都會繼承。你不能刪除它們。

相關問題