Los*_*ace 5 javascript arrays prototype indexof defineproperty
好的peep,所以我有这个代码,但这是一个简化版本:
<!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>
Run Code Online (Sandbox Code Playgroud)
所以我的设置是:
- Chrome v40.0.2214.94 m
- IE v11.0.9600.16428
- IIS v7.5.7600.16385
当我打开任一浏览器并打开上述文件时:
IE ==> C:\ site\proj\default.htm
Chrome ==> file:/// C:/site/proj/default.htm
两个浏览器都显示正确的结果:2...但是当我打开文件时:
IE ==> http:// portal /proj/default.htm
Chrome ==> http:// portal /proj/default.htm
其中portal是localhost站点的名称,在IIS中进行设置.
IE显示undefined并抛出控制台错误:
对象不支持属性或方法'defineProperty'
虽然Chrome浏览器仍显示2正常.
是否IIS改变"兼容模式"的IE浏览器什么的,还是我只是需要更新到新版本的IIS?
我.hta第一次玩文件和我正在写一个Array.prototype.indexOf属性,因为我在尝试访问.indexOf数组时得到了类似的错误消息...
事实是,我想让新indexOf属性可枚举,所以我习惯Object.defineProperty将属性设置为可枚举,这就是我在Stack'上的结果......
| 归档时间: |
|
| 查看次数: |
5726 次 |
| 最近记录: |