Object.getPrototypeOf()与.prototype
- 论坛
- Object.getPrototypeOf()与.prototype
31 浏览
Object.getPrototypeOf()与.prototype
我正在学习一些JS,并希望有人能用简单的语言解释一下Object.getPrototypeOf()
和.prototype
之间的区别。
function ParentClass() {} function ChildClass() {} ChildClass.prototype = new ParentClass(); var mychild = new ChildClass(); var myparent = new ParentClass(); # .getPrototypeOf Object.getPrototypeOf(ChildClass.prototype) // ParentClass {} Object.getPrototypeOf(mychild) // ParentClass {} Object.getPrototypeOf(ParentClass.prototype) // {} Object.getPrototypeOf(myparent) // ParentClass {} # .prototype ParentClass.prototype // ParentClass {} myparent.prototype // undefined ChildClass.prototype // ParentClass {} mychild.prototype // undefined
看起来好像只能在构造函数上调用.prototype
?还有其他的区别吗?