【发布时间】:2013-10-31 13:16:37
【问题描述】:
如果我运行这个,例如在 jsFiddle 中:
function Animal() {
}
var animal = new Animal();
console.log(animal);
console.log(Animal.prototype);
console.log(animal.__proto__);
然后我在 Chrome 的 DevTool 窗口的控制台中得到这些结果 (3x Animal {}):
Animal {} (index):26
Animal {} (index):27
Animal {} (index):28
在我看来这很令人困惑,因为我们知道只有 Animal.prototype 和 animal.__proto__ 在这种情况下指向同一个对象。还是有合理的理由这样做?
【问题讨论】:
-
好问题。你会提出什么替代方案?
-
你说的是数字吗?
26, 27, 28? -
@thefourtheye 他说日志(动物)显示为
Animal {}。也许应该删除数字以使其更清晰。 -
@thefourtheye no :),我说的是 3x
Animal {}。 -
@Tibos 我已经扩展了我的问题以使其更清楚。