このブログの更新は Twitterアカウント @m_hiyama で通知されます。
Follow @m_hiyama

メールでのご連絡は hiyama{at}chimaira{dot}org まで。

はじめてのメールはスパムと判定されることがあります。最初は、信頼されているドメインから差し障りのない文面を送っていただけると、スパムと判定されにくいと思います。

参照用 記事

とある配列をJavaScriptのfor/inで列挙できない、なんで?

IE6での話です。navigator.mimeTypes(clientInformation.mimeTypesでも同じ)というオブジェクトを、次のようなfor/in文で列挙しようとするとエラーが生じます。


for (var p in navigator.mimeTypes) {
// pで何かする
}

配列オブジェクトであったとしても、インデックス(番号)が、"0", "1", "2" といった文字列として列挙され(pに順次入る)と僕は思っていたのですが(Rhinoではそのような動作をします)、、、よくわかりません。次がテストに使ったファイルです。navigator.pluginsなどでも同様な現象が起きます。


<html>
<head>
<title>test</title>
<script><!--
function show(message) {
document.write(message + "<br>");
}
function objectExists(x) {
return typeof x == 'object' && x != null;
}
//-->
</script>
</head>

<body>
<script><!--

show("* window.location exists: " + objectExists(window.location));
try {
for (var p in window.location) {
show(p);
}
} catch(e) {alert("Error in window.location");}

show("* navigator.mimeTypes exists: " + objectExists(navigator.mimeTypes));
try {
for (var p in navigator.mimeTypes) {
show(p);
}
} catch(e) {alert("Error in navigator.mimeTypes");}
//-->
</script>
</body>
</html>


後で調べようとは思ってますが、どなたか事情をご存じでしょうか。