什么是Chrome控制台显示log()? [英] What is the Chrome console displaying with log()?

查看:134
本文介绍了什么是Chrome控制台显示log()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我可能发现了一个Google Chrome的bug(16.0.912.75米,这是撰写本文时的最新版本)。

I think I may have found a bug with Google Chrome (16.0.912.75 m, the latest stable at the time of this writing).

var FakeFancy = function () {};
console.log(new FakeFancy());

var holder = {
    assignTo : function (func) {
        holder.constructor = func;
    }
};

holder.assignTo(function () { this.type = 'anonymous' });
var globalConstructor = function () { this.type = 'global' }

console.log(new holder.constructor());

如果您在Firefox中运行该块,则会显示列为对象 =本地,很不错。但是,如果您在Chrome中运行它,它会显示

If you run that block in Firefox, it shows both listed as "Object" with the second having type = local, pretty good. But if you run it in Chrome, it shows

> FakeFancy
> globalConstructor.type

如果展开树,则内容是正确的。但我无法弄清楚Chrome会列出哪些内容作为记录每个对象的第一行。因为我没有操纵原型,所以它们应该是不会从任何地方继承的简单旧对象。

If you expand the trees, the contents are correct. But I can't figure out what Chrome is listing as the first line for each object logged. Since I'm not manipulating the prototypes, these should be plain old objects that aren't inheriting from anywhere.

起初,我认为这是WebKit相关的,但我在最新的Safari for Windows(5.1.2 7534.52.7)中尝试过,并且都显示为Object。

At first, I thought it was WebKit related, but I tried in the latest Safari for Windows (5.1.2 7534.52.7) and both show up as "Object".

我怀疑它试图做一些猜测构造函数被从中调用。

I suspect that it's attempting to do some guesswork about where the constructor was called from. Is the anonymous constructor's indirection messing it up?

推荐答案

第一行是
$的结果b $ b

The first line is a result of

console.log(new FakeFancy());

WebKit控制台通常会尝试执行构造函数名称推断来让您知道它是什么类型的对象输出。我的猜测是Chrome中包含的更新版本(与Safari 5.1相对)可以对构造函数声明进行推理,如

The WebKit console generally tries to do "constructor name inference" to let you know what type of object it's outputting. My guess is that the more recent version included with Chrome (as opposed to Safari 5.1) can do inference for constructor declarations like

var FakeFancy = function () {};

而不仅仅是像

function FakeFancy(){}

差距悬殊。

这篇关于什么是Chrome控制台显示log()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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