小编Cri*_*nça的帖子

为什么函数响应.prototype但常规对象不响应?

考虑:

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

5
推荐指数
1
解决办法
72
查看次数