console.log is only available after you have opened the Developer Tools (F12 to toggle it open and closed).
(console.log仅在打开开发人员工具(F12可以将其切换为打开和关闭)后可用。)
Funny thing is that after you've opened it, you can close it, then still post to it via console.log calls, and those will be seen when you reopen it.(有趣的是,在打开它之后,您可以将其关闭,然后仍然通过console.log调用发布到它,并且在您重新打开它们时会看到它们。)
I'm thinking that is a bug of sorts, and may be fixed, but we shall see.(我认为这是种错误,可能已修复,但我们会看到。)
I'll probably just use something like this:
(我可能只会使用这样的东西:)
function trace(s) {
if ('console' in self && 'log' in console) console.log(s)
// the line below you might want to comment out, so it dies silent
// but nice for seeing when the console is available or not.
else alert(s)
}
and even simpler:
(甚至更简单:)
function trace(s) {
try { console.log(s) } catch (e) { alert(s) }
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…