The Object.getPrototypeOf()
method returns the prototype (i.e. the value of the internal [[Prototype]]
property) of the specified object.
Object.getPrototypeOf(obj)
obj
The prototype of the given object. If there are no inherited properties, null
is returned.
var proto = {}; var obj = Object.create(proto); Object.getPrototypeOf(obj) === proto; // true
In ES5, it will throw a TypeError
exception if the obj
parameter isn't an object. In ES2015, the parameter will be coerced to an 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. | Draft |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 5 | Yes | 3.5 | 9 | 12.1 | 5 |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | 4 | Yes | Yes | ? |
Even though older Opera versions don't support Object.getPrototypeOf()
yet, Opera supports the non-standard __proto__
property since Opera 10.50.
Object.prototype.isPrototypeOf()
Object.setPrototypeOf()
Object.prototype.__proto__
Reflect.getPrototypeOf()
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf