为什么 Firefox 3 无法使用 console.log
我有以下内容:
console.log (a.time_ago() + ' ' + b.time_ago());
这是 FireFox 3 中的破坏,这意味着当 FF 在 JS 中命中该行时,它不会再进一步。奇怪的是,如果我打开 Firebug,它不会中断并继续正常运行。 firebug 如何防止这个问题?
我对此很困惑。有没有想过为什么 console.log 会破坏 Firefox 3,但如果 Firebug 打开则不会?
谢谢
I have the following:
console.log (a.time_ago() + ' ' + b.time_ago());
This is breaking in FireFox 3, meaning when FF hits that line in the JS, it goes no further. Strangely if I have Firebug open it doesn't break and continues as normal. Some how firebug prevents this issue?
I'm puzzled on this one. Any thoughts as to why console.log would break firefox 3, but not if firebug is open?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这不仅仅是火狐。您的代码将在每个浏览器中停止工作(Chrome 和 safari(在某些情况下)除外,因为它们与开发人员工具一起内置了 console.log() 。)
这是因为当您没有打开 firebug 时,对象“控制台”未定义。您应该注意不要在代码中留下 console.log() 函数,否则它会在每个浏览器中崩溃。
我想补充一点,我有时会使用这个函数:
然后你可以简单地调用:
它的工作方式与console.log相同,但如果未加载firebug则不会失败(并且键入更短:P)
干杯
This is not just Firefox. Your code will stop working in every browser (except Chrome and safari (in some instances) because they have console.log() built in along with their developer tools.)
It is because when you don't have firebug open, the object "console" is not defined. You should take care never too leave console.log() functions in your code, or it will break in every browser.
I'd like to add that I have sometimes used this function:
Then you can simply call:
and it will work the same way as console.log, but will not fail if firebug is not loaded (and is shorter to type :P)
Cheers
如果该萤火虫关闭,我会覆盖控制台对象。所以,你可以实现后备功能......
问候,
Dyvor
In case, that firebug is closed, I overwrite the console object. So, you can implement fallback functions ...
Greetings,
Dyvor
在 FireFox 中,如果调用控制台时控制台未打开,则会引发 JavaScript 错误。
我将所有 console.log 包装在包装器中以检查控制台 - 您可以将检查包装在控制台调用中,也可以使用不同的名称来别名控制台。
别名
检查控制台
In FireFox if the console isn't open when you call to it a JavaScript error is thrown.
I wrap all my console.log's in a wrapper to check for console - you can either wrap the check around the console call or use a different name to alias console.
Aliasing
Check for console
我总是进行
if (console)
检查以确保控制台确实存在。如果 firebug 没有打开,就好像您正在对一个 null 对象进行操作,这就是它崩溃的原因。I always do a
if (console)
check to make sure the console actually exists. If firebug isn't open it's like you're acting upon a null object, thus why it breaks.Firefox 没有控制台对象。 Firebug 添加了一个。
简单的修复方法是打开 firebug 进行开发,并删除 console.log 语句进行部署。
您还可以创建一个自定义日志函数,
仅当控制台存在时才会记录
Firefox doesn't have a console object. Firebug adds one.
The simply fix is to have firebug open for development and remove console.log statements for deployment.
you can also make a custom log function like
that will log only if console exists
为了让 Firefox 3.0 可靠地避免抱怨,请使用以下命令...
To keep Firefox 3.0 from complaining reliably use the following...