在线文档教程

Object.getPrototypeOf

Object.getPrototypeOf

Object.getPrototypeOf() 方法返回指定对象的原型 ( 即, 内部[[Prototype]]属性)。

语法

Object.getPrototypeOf(obj)

参数

obj要设置其原型的对象。

返回值

给定对象的原型。如果没有继承的属性,null则返回。

Examples

var proto = {}; var obj = Object.create(proto Object.getPrototypeOf(obj) === proto; // true

注意事项

在ES5中,TypeError如果obj参数不是一个对象,它将会抛出一个异常。在ES2015中,参数将被强制为一个Object

Object.getPrototypeOf('foo' // TypeError: "foo" is not an object (ES5 code) Object.getPrototypeOf('foo' // String.prototype (ES2015 code)

规范

SpecificationStatusComment
ECMAScript 5.1 (ECMA-262)The definition of 'Object.getPrototypeOf' in that specification.StandardInitial definition.
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Object.getPrototypeOf' in that specification.Standard
ECMAScript Latest Draft (ECMA-262)The definition of 'Object.getPrototypeOf' in that specification.Living Standard

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support5(Yes)3.5912.105

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support(Yes)(Yes)(Yes)1No(Yes)(Yes)