好吧,我有这个代码,但这是简体版本:
<!DOCTYPE html>
<html>
<head>
<title>_</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<script>
Object.defineProperty(
Array.prototype,'len',{get:
function(){return this.length}
});
function pop(){
ary=['abc',123];
d1.innerText=ary.len;
}
</script>
</head>
<body onload="pop()">
<div id="d1">d1</div>
</body>
</html>
所以我的设置是:
- Chrome v40.0.2214.94 m
- IE v11.0.9600.16428
- IIS v7.5.7600.16385
当我打开任一浏览器并以上述方式打开上述文件时:
IE ==> C:\ site \ proj \ default.htmChrome ==> file:/// C:/site/proj/default.htm
[两个浏览器都显示正确的结果:2
...但是,当我这样打开文件时:
IE ==> http:// 门户 / proj / default.htmChrome ==> http:// 门户 / proj / default.htm
其中portal是localhost站点的名称,在IIS中进行设置。
IE显示undefined
并抛出控制台错误:
对象不支持属性或方法'defineProperty'
虽然Chrome仍正确显示2
。
.hta
文件,我正在编写Array.prototype.indexOf
属性,因为在尝试访问数组上的.indexOf
时收到与上述类似的错误消息...indexOf
属性enumerable
,所以我使用Object.defineProperty
将属性设置为enumerable,这就是我最终在Stack'上使用的方式...”
Ok peep,所以我有这段代码,但这是一个简化的版本: