Console.log in IE8: A Mysteriously Disappearing Act
In IE8's beta release, the console.log function emerged as a promising debugging tool. However, to many developers' dismay, it vanished in the final version. What happened?
Unveiling the Reality
According to Microsoft, console.log is accessible only through the Developer Tools window. By pressing F12, you can toggle the tools on and off. Intriguingly, once opened, you can close the window and continue utilizing console.log. The results will be visible upon reopening the tools.
Potential Bugs and Workarounds
This behavior suggests a potential bug, which Microsoft may address in the future. Until then, developers seeking debugging functionality can employ workarounds like:
function trace(s) { if ('console' in self & '&' & 'log' in console) console.log(s) // else alert(s) // You might want to comment this out to suppress silent errors }
Or an even simpler approach:
function trace(s) { try { console.log(s); } catch (e) { alert(s); } }
These methods allow developers to keep track of debugging information in IE8, despite the absence of console.log in the main browser window.
以上是為什麼「console.log」在 IE8 最終版本中消失了?的詳細內容。更多資訊請關注PHP中文網其他相關文章!