创建原型继承时代理实例更改 类?

Surrogate instance changing classes when creating prototypal inheritance?

所以我正在尝试使用代理方法设置原型继承,并且我 运行 变成了一种对我来说似乎很奇怪的行为。这是我的 classes:

function Animal(name) { 
    this.name = name;
}

Animal.prototype.eat = function() { 
    console.log("mmm... food...")
};

function Dog(name) { 
    this.name = name 
};

var Surrogate = function() {}
Surrogate.prototype = Animal.prototype;

现在,我想将 Animal 设置为基础 class。如果我创建代理实例:

浏览器控制台显示 s 是 Surrogate 的一个实例。

但是,当我将 Dog class 的原型设置为 Surrogate 的实例时:

它变成了Animal的一个实例?为什么会这样?这是正确的还是我解释错了?

using the surrogate method

提示:为此使用 Object.create,这已经成为标准十年了:-)

It becomes an instance of Animal?

没有。它仍然是完全相同的对象,并且功能没有改变。 instanceof Animal 和以前一样。

您在控制台中看到的 Animal {} 是调试器的自定义显示选择。

Why is this happening?

我的猜测是您会看到 internal optimisation that occurs when an object is assigned as the .prototype of a function 的副作用,这只能在调试器中观察到。