Javascript 向对象原型添加可枚举函数时出现未捕获的TypeError

Javascript 向对象原型添加可枚举函数时出现未捕获的TypeError,javascript,function,prototype,typeerror,enumerable,Javascript,Function,Prototype,Typeerror,Enumerable,每当我向对象的原型中添加可枚举函数时,就会出现一些类型错误 jquery-1.10.2.js:2451 Uncaught TypeError: matchExpr[type].exec is not a function at tokenize (jquery-1.10.2.js:2451) at Function.Sizzle [as find] (jquery-1.10.2.js:1269) at init.find (jquery-1.10.2.js:5744)

每当我向对象的原型中添加可枚举函数时,就会出现一些类型错误

jquery-1.10.2.js:2451 Uncaught TypeError: matchExpr[type].exec is not a function
    at tokenize (jquery-1.10.2.js:2451)
    at Function.Sizzle [as find] (jquery-1.10.2.js:1269)
    at init.find (jquery-1.10.2.js:5744)
    at change-project-controller.js:4
    at change-project-controller.js:255
tokenize @ jquery-1.10.2.js:2451
Sizzle @ jquery-1.10.2.js:1269
find @ jquery-1.10.2.js:5744
(anonymous) @ change-project-controller.js:4
(anonymous) @ change-project-controller.js:255

jquery-1.10.2.js:2451 Uncaught TypeError: matchExpr[type].exec is not a function
    at tokenize (jquery-1.10.2.js:2451)
    at Function.Sizzle [as find] (jquery-1.10.2.js:1269)
    at init.find (jquery-1.10.2.js:5744)
    at filter-by-registrant-controller.js:10
    at filter-by-registrant-controller.js:179
tokenize @ jquery-1.10.2.js:2451
Sizzle @ jquery-1.10.2.js:1269
find @ jquery-1.10.2.js:5744
(anonymous) @ filter-by-registrant-controller.js:10
(anonymous) @ filter-by-registrant-controller.js:179

jquery-1.10.2.js:2451 Uncaught TypeError: matchExpr[type].exec is not a function
    at tokenize (jquery-1.10.2.js:2451)
    at Function.Sizzle [as find] (jquery-1.10.2.js:1269)
    at init.find (jquery-1.10.2.js:5744)
    at registrations-controller.js:6
    at registrations-controller.js:412
tokenize @ jquery-1.10.2.js:2451
Sizzle @ jquery-1.10.2.js:1269
find @ jquery-1.10.2.js:5744
(anonymous) @ registrations-controller.js:6
(anonymous) @ registrations-controller.js:412

Index:290 Uncaught TypeError: Cannot read property 'registerFilter' of undefined
    at Index:290
(anonymous) @ Index:290
请注意,四个错误中的最后一个与jQuery无关

这是导致错误发生的代码:

Object.defineProperty(Object.prototype, "select", {

    enumerable: true,
    value: function () {

        return "hello world";

    }

});
如果将函数添加为不可枚举,则不会出现错误,如下所示:

Object.defineProperty(Object.prototype, "select", {

    enumerable: false,
    value: function () {

        return "hello world";

    }

});
请注意,唯一的区别是可枚举成员设置为
false
。另外,如果我更改要添加到数组而不是对象的可枚举函数,代码运行良好

我正在处理的项目不是我的,因此我无法共享它,而且我还没有成功地在JSFIDLE或简单的HTML文件中复制错误

每当我向对象的原型中添加可枚举函数时,就会出现一些类型错误

jquery-1.10.2.js:2451 Uncaught TypeError: matchExpr[type].exec is not a function
    at tokenize (jquery-1.10.2.js:2451)
    at Function.Sizzle [as find] (jquery-1.10.2.js:1269)
    at init.find (jquery-1.10.2.js:5744)
    at change-project-controller.js:4
    at change-project-controller.js:255
tokenize @ jquery-1.10.2.js:2451
Sizzle @ jquery-1.10.2.js:1269
find @ jquery-1.10.2.js:5744
(anonymous) @ change-project-controller.js:4
(anonymous) @ change-project-controller.js:255

jquery-1.10.2.js:2451 Uncaught TypeError: matchExpr[type].exec is not a function
    at tokenize (jquery-1.10.2.js:2451)
    at Function.Sizzle [as find] (jquery-1.10.2.js:1269)
    at init.find (jquery-1.10.2.js:5744)
    at filter-by-registrant-controller.js:10
    at filter-by-registrant-controller.js:179
tokenize @ jquery-1.10.2.js:2451
Sizzle @ jquery-1.10.2.js:1269
find @ jquery-1.10.2.js:5744
(anonymous) @ filter-by-registrant-controller.js:10
(anonymous) @ filter-by-registrant-controller.js:179

jquery-1.10.2.js:2451 Uncaught TypeError: matchExpr[type].exec is not a function
    at tokenize (jquery-1.10.2.js:2451)
    at Function.Sizzle [as find] (jquery-1.10.2.js:1269)
    at init.find (jquery-1.10.2.js:5744)
    at registrations-controller.js:6
    at registrations-controller.js:412
tokenize @ jquery-1.10.2.js:2451
Sizzle @ jquery-1.10.2.js:1269
find @ jquery-1.10.2.js:5744
(anonymous) @ registrations-controller.js:6
(anonymous) @ registrations-controller.js:412

Index:290 Uncaught TypeError: Cannot read property 'registerFilter' of undefined
    at Index:290
(anonymous) @ Index:290
不要这样做。正如您所发现的,这样做会破坏许多毫无戒心的代码。默认情况下,空白对象没有可枚举属性。例如:

var o={};
for(o中的变量名称){
log(“这一行永远不会在合理的世界中运行。”);
}

控制台日志(“结束”)