0

有没有办法以不包含在循环中的方式将函数添加到对象原型?

前任:

Object.prototype.stuff = function(){};
var obj = {'hello':1};
for(var i in obj){
    console.log(i);
}
//it will log: hello, stuff
//I'd want it to only log hello,
4

1 回答 1

0
Object.defineProperty(Object.prototype, "stuff", {
    enumerable: false,
    value: function(){
        //...
    }
}); 
于 2014-07-12T19:01:13.167 回答