铬记录了错误的javascript值 [英] Chromium logs wrong javascript values

查看:113
本文介绍了铬记录了错误的javascript值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建带有嵌套数组网格来表示图块的游戏时,我试图确定相邻"图块类型,并遇到编码错误.

While building a game where there is nested array grid to represent tiles , i was trying to determine "neighboring" tiles type , and ran into a coding mistake.

当我尝试调试时,我想console.log一些对象,但是我的浏览器却给了我奇怪的输出.当对象写在一行上时,值似乎是正确的(除了我的错误),但是当我想显示对象的其余部分(单击并向下滚动)时,它显示的是完全不同的值.这是我造成的吗?

When i tried to debug , i wanted to console.log some objects , but my browser gave me weird output. When the object is written on one line , the values seem to be somewhat right ( except for that mistake of mine ) but when i wanted to display the rest of the object (click and roll-down) , it showed me entirely different values. Is this caused by me ?

为更好地说明,这是一个屏幕截图

For better illustration , here is a screenshot

这样声明对象

var TileFactory = function(){
this.l={
    x:null,
    y:null
};
this.neighbours={
    top:null,
    topR:null,
    topL:null,
    r:null,
    l:null,
    bot:null,
    botR:null,
    botL:null
    };
this.buffer;
};

然后,通过方法(条件链)几次快速地对此进行操作

And then , this is manipulated via method several times ( chain of conditions ) rapidly

推荐答案

有多个答案,其中包含更详细的解释和解决方案.但是,在控制台视图中扩展对象时,控制台将输出对象的最新状态.如果从未真正查看过这些对象,也许这样做可以减少内存使用.因此,如果在记录对象后该对象发生了突变,则在展开该对象时会看到不同的结果.

There are multiple answers out there with more detailed explanation and solutions. But when expanding an object in console view, the console output the latest state of the object. Perhaps doing so to reduce memory use in case those objects was never really viewed. So if the object has mutated after you logged it, you see a different result when you expand it.

如果对象没有循环结构并且没有功能,将其记录为json字符串将解决此问题.如果它确实具有循环结构和/或功能,也许您需要找到一些深层的对象克隆方法.

If the object has no cyclic structure and has no functions, logging it as json string would solve the issue. If it does have cyclic structure and/or functions, perhaps you need to find some deep object cloning methods.

就我个人而言,我会避免使用这种日志记录技术.无论这样记录任何对象,都无法对其进行gc'ed.确定应在发布代码之前删除这些日志.

Personally I'd avoid using these kind of logging technique though. Whatever object is logged like this, it cannot be gc'ed. Definite should remove those logs before publishing code.

这篇关于铬记录了错误的javascript值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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