Javascript ES5/IE8设置不可枚举的属性
我使用一个向数组类添加一些属性的库。 例如:Javascript ES5/IE8设置不可枚举的属性,javascript,properties,internet-explorer-8,ecmascript-5,enumerable,Javascript,Properties,Internet Explorer 8,Ecmascript 5,Enumerable,我使用一个向数组类添加一些属性的库。 例如: Array.prototype.realFunction = function(){return true;} 这些添加的属性是可枚举的,因此它会给循环(for…in)(来自MS:D的代码)带来一些问题 所以,我编写了一些代码,将这些属性设置为不可枚举,但在IE8上不起作用 for(var p in Array.prototype) { var desc = Object.getOwnPropertyDescriptor(Arr
Array.prototype.realFunction = function(){return true;}
这些添加的属性是可枚举的,因此它会给循环(for…in)(来自MS:D的代码)带来一些问题
所以,我编写了一些代码,将这些属性设置为不可枚举,但在IE8上不起作用
for(var p in Array.prototype)
{
var desc = Object.getOwnPropertyDescriptor(Array.prototype, p);
if(desc != null && desc.enumerable) {
desc.enumerable = false;
Object.defineProperty(Array.prototype, p, desc);
}
}
我该怎么做
谢谢你的帮助,我要死了
致以最诚挚的问候可能的重复不是重复。怎么会这样?您试图在IE8中创建一个不可枚举的属性,对吗?