1 回答

TA貢獻1772條經驗 獲得超8個贊
1.MSDN上這么說:
Internet Explorer 8 does not include enumerations of properties that have the same name as built-in properties of a prototype object. All document modes in Internet Explorer 9 include these properties in the enumeration.
大意是IE8對于與原型內置屬性同名的屬性(這里的原型指Object)不進行枚舉,IE9則認為這些屬性是可枚舉的。
toString
是Object
的內置屬性,所以不枚舉,沒有問題;
2.StackOverflow上有個類似的問題,提問者在實際使用過程中發現了同樣的問題
I've run into a very odd issue with IE8's JS engine (possibly previous versions as well, but NOT IE9 in IE8 mode since the JS engine doesn't fallback). Simplified example:
var foo = { toString : 42, x : 22 };for(var n in foo){ console.log(n) }// result: "x"
答案結論類似,不過更詳細地指出了實現原理是DontEnum
屬性:
In IE < 9, JScript will skip over any property in any object where there is a same-named property in the object's prototype chain that has the DontEnum attribute.
MDN上對DontEnum
的說明,指出其是在ES3初次實現,后來在ES5中改了名字。
答案還給了個MDN的連接,可惜不能訪問了,google快照也查不到。不過答案中提到了一個詞叫"JScript DontEnum Bug",根據這個去搜索可以查到一些結果,以及幾個SO的問題,結論類似。
綜上我們可以判斷,這個bug是的確存在過的,影響范圍是IE4(不確定)~IE9之間所有IE瀏覽器。
至于沒有測試成功,原因就不清楚了。我也不會下個IE5去測試??赡鼙恍迯土税桑海?/p>
添加回答
舉報