Javascript 向对象添加prototype时如何排除某些js类型
一旦我将以下代码添加到我的html页面,我就会得到:Javascript 向对象添加prototype时如何排除某些js类型,javascript,jquery,prototype,Javascript,Jquery,Prototype,一旦我将以下代码添加到我的html页面,我就会得到: Uncaught TypeError: Object function (constrname) { if(this.constructor.name===constrname){ return true; } return false; } has no method 'exec' 这是导致错误的原型: Object.prototype.isInstanceOf=function(constrna
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
我可以在为对象类型定义新原型时排除某些类型吗。例如,exclude:jQuery类型
我尝试了以下代码,但无效:
Object.prototype.isInstanceOf=function(constrname) {
if(!(this instanceof jQuery)){
//write here code
}
}
不,这是不可能的。原型继承的全部要点是原型上的对象由每个后代继承。您无法删除它们。否。请改为使其不可枚举。更好的是,根本不要这样做。你能详细说明导致这个错误的条件吗?我认为jQuery写得足够好,不会在这样的事情上断章取义。@SLaks感谢您的回答;但是,我应该让谁使其不可枚举,以及如何使其不可枚举?