[英]List all Array.prototype functions in IE8-
是否可以以跨瀏覽器友好的方式遍歷所有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之前在IE中獲得的列表:
concat,構造函數,join,length,pop,push,reverse,shift,slice,sort,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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.