DevTools如何确定对象的构造函数名称? [英] How does DevTools determine an object's constructor's name?

查看:231
本文介绍了DevTools如何确定对象的构造函数名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Chrome v22.0.1229.94 m,而不是它应该重要,但只是为了: - )

I'm using Chrome v22.0.1229.94 m, not that it should matter, but just in case :-)

可移植性关心我。

我有两个函数foo和bar:

I have two functions, foo and bar:

var foo = function() {
  ...
}
function bar() {
  ...
}

那么如果我使用它们创建对象:

then if I create objects using them:

f1 = new foo();
b1 = new bar();

我可以获取bar的构造函数名,但不能使用foo:

I can get the constructor's name for bar, but nor for foo:

> f1.constructor.name  ==> ""
> b1.constructor.name  ==> "bar"

但在这两种情况下,DevTools控制台将显示名称foo我检查变量 f1 b1

yet in both cases DevTools console will show the names "foo" and "bar" when I inspect the variables f1 and b1.

如何提取名称

How do I extract the name foo for f1 as DevTools is able to?

推荐答案

解析阶段,通过其API暴露这些信息。您将无法使用正常的对象属性提取此信息。

V8 can perform function name inference at the parsing stage, exposing this information via its APIs. You will not be able to extract this info using the normal object properties.

这篇关于DevTools如何确定对象的构造函数名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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