考虑:
function Foo() {}
var x = new Foo();
Run Code Online (Sandbox Code Playgroud)
现在x和Foo有相同的原型,但只有Foo响应.prototype:
Object.getPrototype(x) === Foo.prototype // true
x.prototype === Foo.prototype // false
Foo.prototype // Foo {} (depending on which browser)
x.prototype // undefined
Run Code Online (Sandbox Code Playgroud)
为什么不起作用x.prototype,但Foo.prototype确实有效?
javascript prototype undefined new-operator prototypal-inheritance