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)
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 5.1 (ECMA-262)The definition of 'Object.getPrototypeOf' in that specification. | Standard | Initial 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 | |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | 5 | (Yes) | 3.5 | 9 | 12.10 | 5 |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | 1 | No | (Yes) | (Yes) |