firebug/chromedevtools console.group 缩进错误吗?

发布于 2024-11-16 22:19:28 字数 1406 浏览 11 评论 0原文

我不确定这是否真的是一个问题,或者更多的是一个观察,甚至是一个错误。

在我的 javascript 代码中,我使用许多 console.log 和 console.group 语句来跟踪内部发生的情况。该代码还执行一些递归,因此确保组的缩进正确非常重要。

//working dummy code illustrating the problem
var data=3;
var demo=(function(){
    var internal=function(){
        console.group("internal");
        console.log("some smart shit");
        console.groupEnd();
    }

    console.group("inside the closure1");
    console.group("inside the closure2");

    internal();

    if (data===5){
        console.log("funny Things");
    }

    console.groupEnd();
    console.log("some smart shit 1");
    console.groupEnd();

}( data ));
console.log("Indentation correct?!");

如果执行了所有代码块,则控制台中构建的树会深入,但会向上冒泡回到层次结构的根级别。现在,如果一个块不执行其他块并且控制台没有记录任何内容,则在离开代码块后缩进仍保持在 +1。

改变

var data=5
in the obove dummy code to
var data=3
and you'll see that the indentation will be wrong!

更一般地说; 在每次调用 console.group 时嵌套 console.group 而不使用 console.log 会导致错误缩进!

我知道,ChromeDevTeam 已经提到了 firebug 控制台 api 同时实现 chromedevtools 并假设此行为在 firebug 中是相同的。

我现在想问是否有人经历过同样的行为? 有谁知道这种行为是否符合预期? 最重要的是;有谁知道解决这个缩进问题的解决方法? 当然,每次我打开一个小组时,我都可以 console.log 一些东西,但这并不是真正的想法,如果你问我..

感谢有关此主题的任何有用信息,抱歉,如果这个问题有点蹩脚: (

//Edit Nr2 -> 我已经更新了代码来说明问题。它现在生成了所描述的错误缩进(与我的预期相反)。

I'm not sure, if this is really a question or more an observation - or even a bug.

Throughout my javascript code I'm using many console.log and console.group statements to track whats happening internally. The code also does some recursion, thus making it quite important to have the indentation of the groups correct.

//working dummy code illustrating the problem
var data=3;
var demo=(function(){
    var internal=function(){
        console.group("internal");
        console.log("some smart shit");
        console.groupEnd();
    }

    console.group("inside the closure1");
    console.group("inside the closure2");

    internal();

    if (data===5){
        console.log("funny Things");
    }

    console.groupEnd();
    console.log("some smart shit 1");
    console.groupEnd();

}( data ));
console.log("Indentation correct?!");

If all code blocks are executed, the tree built in the console goes deep, but bubbles back up to the root level of the hierarchy. Now, if a block doesn't execute an other block and nothing is logged to the console, the indentation remains at +1 after leaving the code block.

Change the

var data=5

in the obove dummy code to

var data=3

and you'll see that the indentation will be wrong!

More generally speaking; Nesting console.group's without using a console.log for every time console.group was called results in false indentation!

I know, that the ChromeDevTeam have referred to the firebug console api while implementing the chromedevtools and assume this behavior is the same in firebug.

I now question if anybody has experienced the same behavior?
Does anybody know if this behavior is as expected?
And most importantly; does anyone know a workaround to fix this indentation problem?
Of course, I could console.log something every time I open up a group, but this isn't really the idea, if you ask me..

Thanks for any helpful information on this topic and sorry, if this question is kinda lame :(

//Edit Nr2 -> I've updated the code to illustrate the problem. It now generates the false indentation as described (against what I am expecting).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天邊彩虹 2024-11-23 22:19:28

我就此问题提交了一个错误:https://bugs.webkit.org/show_bug.cgi ?id=63455

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文