Object.getPrototypeOf()与Javascript中的Object.constructor.prototype是否相同? [英] is Object.getPrototypeOf() same as Object.constructor.prototype in Javascript?
本文介绍了Object.getPrototypeOf()与Javascript中的Object.constructor.prototype是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Object.getPrototypeOf(obj)
和 obj.constructor.prototype
之间是否有区别?还是这两个引用相同的内容?
Is there a difference between Object.getPrototypeOf(obj)
and obj.constructor.prototype
? Or are these two referencing the same thing?
推荐答案
否
它返回内部 [[Prototype]]
值。
It returns the internal [[Prototype]]
value.
例如:
var o = Object.create(null);
Object.getPrototypeOf(o); // null
o.constructor.prototype; // error
var p = {};
var o = Object.create(p);
Object.getPrototypeOf(o); // p
o.constructor.prototype; // Object.prototype
o.constructor.prototype
仅适用于通过 new ConstructorFunction
创建的对象,或者您已手动设置 Prototype.prototype.constructor ===原型$ c $的对象c>关系。
o.constructor.prototype
only works with objects created through new ConstructorFunction
or where you have manually set the Prototype.prototype.constructor === Prototype
relationship.
这篇关于Object.getPrototypeOf()与Javascript中的Object.constructor.prototype是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文