为什么Chrome显示的值是在数组被删除前从数组中删除的? [英] Why is Chrome showing a value as being removed from an array before it has been?

查看:85
本文介绍了为什么Chrome显示的值是在数组被删除前从数组中删除的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

在删除该值之前,Chrome的js控制台正在显示一个包含已删除值的数组。为什么?

Chrome's js console is showing an array with a deleted value before the value is deleted. Why?

jsFiddle演示了这种行为

jsFiddle that demonstrates this behavior.

var list=[];
list.push("one");
list.push("two");
list.push("three");
console.log(list);                        //["two", "three", undefined × 1] 
$("#output").append(JSON.stringify(list));//["one","two","three"]

list.shift();

$("#output").append($("<br>"));

console.log(list);                        //["two", "three"] 
$("#output").append(JSON.stringify(list));//["two","three"]


推荐答案

Chrome console.log 是延迟;在这种情况下,我相信程序结束。

In Chrome console.log is "delayed"; in this case to the end of the Program I believe.

也就是说,在Chrome中, console.log 不立即对输入对象进行字符串化,而是在稍后一段时间(此时对象已被修改)之后执行字符串化,但在它实际显示结果之前,

That is, in Chrome, console.log does not stringify the input object immediately but rather performs the stringification "some time later" (after which the object has been modified in this case) but before it actually displays the result,

console.log(JSON.stringify(list))会显示预期的结果。

这被报告为一个错误 webkit base:

This was reported as a bug as far back as Chrome 5 (the bug-fix target is Mstone-22, so not Chrome 20/21?) and a fix has been added to the webkit base:


从今天开始,将一个对象(数组)转储到控制台将导致对象的属性在控制台对象扩展时被读取(即延迟)。这意味着在改变它的同时转储同一对象将很难使用控制台进行调试。

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.

这篇关于为什么Chrome显示的值是在数组被删除前从数组中删除的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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