控制台日志记录对象显示2个不同的值 [英] Console logging object shows 2 different values

查看:56
本文介绍了控制台日志记录对象显示2个不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是疯了,还是吗?如果我直接访问出发日期我会得到正确的值2016-05-18.

This is insane, or is it?! If I access departuredate directly I get the correct value of 2016-05-18.

console.log(searchFactory.search.searchparams.journeys[0].departuredate); // 2016-05-18 
console.log(searchFactory.search.searchparams.journeys[0] //stored in the object as 2010-05-10 

但是,如果我如附件屏幕快照中那样对整个对象进行console.log(),它将重置为今天的日期.这怎么可能呢?最终,该值分配给了我的工厂,最终是2016年5月10日-今天.沿这条线的某个地方,日期已更改为今天的日期,对于我一生来说,我不知道该怎么做.

However if I console.log() the entire object as in the attached screenshot, it is reset to todays date. How is that even possible? Ultimately the value is assigned to my Factory, which ends up being 2016-05-10 - today. Somewhere along the line the date is getting changed to todays date and for the life of me I don't understand how.

$scope.$watch('date', function(newDate) {
    searchFactory.search.searchparams.journeys[0].departuredate = moment(newDate.startDate).format("YYYY-MM-DD");
    searchFactory.search.searchparams.journeys[0].returndate = moment(newDate.endDate).format("YYYY-MM-DD");
    console.log(searchFactory.search.searchparams.journeys[0]);    
});

我要疯了,试图解决这个问题.

I am going insane, trying to figure this out.

本质上,我正在监视日期范围项目,该项目所有工作都很好.然后将newDate分配到我的工厂进行存储和以后使用.如您所见,我只是在记录对象以查看值.您可以在屏幕截图中看到它如何带有两个不同的值...据我所知,到目前为止,这是不可能的.

Essentially I am watching the date scope item, which all workds fine. The newDate then gets assigned to my factory for storage and later use. As you can see I am simply logging the object to see the value. You can see in the screenshot how it carries two different values... which to my believe was impossible until now.

任何指针将不胜感激.

推荐答案

这是(a)="a href =" https://bugs.webkit.org/show_bug.cgi?id=35801"rel =" nofollow> Webkit中的已知错误在4年后仍未发布.

This is(was) a known bug in webkit that still has yet to hit chrome 4 years later.

从今天开始,将对象(数组)转储到控制台中将导致对象的属性被读取控制台对象扩展后(即懒惰地).这意味着在转储相同对象的同时进行更改将很难使用控制台进行调试.

As of today, dumping an object (array) into console will result in objects' properties being read upon console object expansion (i.e. lazily). This means that dumping the same object while mutating it will be hard to debug using the console.

此更改开始在对象/数组生成它们时生成简短的预览记录并将此信息传递到前端.这仅在前端时发生已打开,仅适用于console.log(),不适用于实时控制台交互.

This change starts generating abbreviated previews for objects / arrays at the moment of their logging and passes this information along into the front-end. This only happens when the front-end is already opened, it only works for console.log(), not live console interaction.

此处看到.

您可以使用 <同时记录code> obj.toString().

这篇关于控制台日志记录对象显示2个不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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