为什么Firefox 3打破了console.log [英] Why is Firefox 3 breaking with console.log

查看:155
本文介绍了为什么Firefox 3打破了console.log的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  console.log(a.time_ago()+''+ b.time_ago() ); 

这是FireFox 3的突破,这意味着当FF在JS中击中那条线时, 。奇怪的是,如果我有Firebug打开它不会中断,并继续正常。一些如何防止这个问题的萤火虫?



我对此感到困惑。任何想到为什么console.log会打破firefox 3,但不是如果萤火虫打开?



谢谢

解决方案

这不仅仅是Firefox。您的代码将停止在每个浏览器(除了Chrome和Safari浏览器(在某些情况下),因为他们有内置的console.log()以及他们的开发工具。)



这是因为当你没有萤火虫打开,对象控制台没有定义。你应该注意,不要在你的代码中留下console.log()函数,否则它会在每个浏览器中断开。




我想补充一点,我有时使用这个函数:

$ p $ function log() {
if(typeof console =='undefined'){
return;
}
console.log.apply(console,arguments);





$ b然后你可以直接调用:

  log(somevar,anothervar); 

它将以与console.log相同的方式运行,但是如果没有加载萤火虫(而且比较短):

干杯


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

解决方案

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:

function log () {
    if (typeof console == 'undefined') {
        return;
    }
    console.log.apply(console, arguments);
}

Then you can simply call:

log(somevar, anothervar);

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

这篇关于为什么Firefox 3打破了console.log的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆