Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 向对象添加prototype时如何排除某些js类型_Javascript_Jquery_Prototype - Fatal编程技术网

Javascript 向对象添加prototype时如何排除某些js类型

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

一旦我将以下代码添加到我的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

我可以在为对象类型定义新原型时排除某些类型吗。例如,exclude:jQuery类型

我尝试了以下代码,但无效:

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

不,这是不可能的。原型继承的全部要点是原型上的对象由每个后代继承。您无法删除它们。

否。请改为使其不可枚举。更好的是,根本不要这样做。你能详细说明导致这个错误的条件吗?我认为jQuery写得足够好,不会在这样的事情上断章取义。@SLaks感谢您的回答;但是,我应该让谁使其不可枚举,以及如何使其不可枚举?