在IE8-中列出所有array.protype函数



是否可以以跨浏览器友好的方式循环遍历所有JavaScript Array.prototype函数名称?我知道这在IE9 和现代浏览器中有效:

var names = Object.getOwnPropertyNames(Array.prototype);
names.forEach(function(name) {
    console.log(name); // function name
});   

是否有一种方法可以在IE8&中获取相同的列表。IE7?我尝试了:

for(var key in Array.prototype) {
    console.log(key); // undefined
}

如果您要在版本9之前找到IE浏览器中支持的内容,则可以假设它是IE9列表的子集,并且不支持那些。

这是您在#9之前获得的列表:

CONCAT,构造函数,加入,长度,pop,Pusp,Revers,Shift,Shift,Shift,slice,sert,sert,splice,tolocalestring,toString,unshift

您可以测试 -

<!doctype html>
<html lang="en">
<head>
<meta charset= "utf-8">
<title>Small Page</title>
<style>
</style>
<script>
onload= function(){
var testnames= ['concat', 'constructor', 'every', 'filter', 'forEach',
'indexOf', 'join', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce',
'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice',
'toLocaleString', 'toString', 'unshift'],
    L= 23;
    while(L){
        if(!(testnames[--L]in Array.prototype)) testnames.splice(L, 1);
    }
    document.getElementsByTagName('textarea')[0].value= testnames;
}
</script>
</head>
<body>
<p>   <textarea rows="8" cols="60"> </textarea>     </p>
</body>
</html>

最新更新