有没有办法以一种不包含在循环中的方式向Object Prototype添加一个函数?
例如:
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,
答案 0 :(得分:0)
Object.defineProperty(Object.prototype, "stuff", {
enumerable: false,
value: function(){
//...
}
});