为什么google chromes控制台延迟? [英] Why is google chromes console delayed?

查看:482
本文介绍了为什么google chromes控制台延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:


基本上我发现google chrome与它的开发者工具存在问题。



以此片段为例:

  console.log($(this).find('.buttons .cancel')); 
$(this).find('.buttons .cancel')。remove();

当该片段被触发时,如果有两个项目与这些选择器匹配,则Google Chrome输出 [,] 。基本上它是查找元素,但它显示数据似乎比应该慢。



我希望能够记录正在删除的项目,但现在我必须首先运行它,而不需要 .remove()行。然后在知道工作正常后,我可以使用 remove()函数重新运行它。

解决方案

考虑以下测试:


  • a = {a:'a'} 。它返回一个对象。
  • aa ='b'

  • 第一个命令。它显示 a:b



在Chrome开发者控制台中第一次打开时所处的状态。对于(伪)数组,重要的是当控制台到达时对象的状态。这可能是正常的JavaScript返回后(很难说为什么。很可能性能的原因)。



你可以通过记录不变的元素来处理这个问题,例如:


  • 原始值: console.log(hello)

  • 克隆DOM节点或jQuery对象: console.log($(this).find(。buttons .cancel)。clone())

    C>的console.log(文件);调试器;


    Possible Duplicate:
    Is Chrome’s JavaScript console lazy about evaluating arrays?

    Basically what I am finding is that google chrome is having issues with it's developer tools.

    Take this snippet for example:

    console.log($(this).find(' .buttons .cancel'));
    $(this).find(' .buttons .cancel').remove();
    

    When that snippet is triggered, if there are two items that match those selectors google chrome outputs [, ]. basically it is finding the elements, but it seems to be slower at displaying the data than it should be.

    I want to be able to log what items I am deleting, but as it stands I must run it first without the .remove() line. and then after I know that is working I can run it again with the remove() function.

    解决方案

    Consider the following test:

    • a={a:'a'}. It returns an object.
    • a.a='b'
    • expand the return from the first command. It shows a: "b"

    So, an object is always shown in the state it is in when it first gets open in the Chrome developer console. For (pseudo-)arrays, what matters is the state of the object when the console gets to it. This could be right after the normal javascript returns (hard to tell why. Performance reasons, perhaps).

    You can handle this by always logging elements that don't change, such as:

    • primitive values: console.log("hello")
    • clones of DOM nodes or jQuery objects: console.log($(this).find(".buttons .cancel").clone())

    If logging an immutable object is not an option, you can still log while tracing the code: console.log(document); debugger;

    这篇关于为什么google chromes控制台延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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