Object.getPrototypeOf()

The Object.getPrototypeOf() method returns the prototype (i.e. the value of the internal [[Prototype]] property) of the specified object.

Syntax

JavaScript
Object.getPrototypeOf(<var>obj</var>)

Parameters

obj
The object whose prototype is to be returned.

Return value

The prototype of the given object. If there are no inherited properties, null is returned.

Examples

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

Notes

In ES5, it will throw a TypeError exception if the obj parameter isn't an object. In ES6, the parameter will be coerced to an Object.

JavaScript
Object.getPrototypeOf("foo");
// TypeError: "foo" is not an object (ES5 code)
Object.getPrototypeOf("foo");
// String.prototype                  (ES6 code)

Specifications

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.getProtoypeOf' in that specification.
Standard  
ECMAScript 2017 Draft (ECMA-262)
The definition of 'Object.getProtoypeOf' in that specification.
Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 3.5 (1.9.1) 9 12.10 5
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ? ?

Opera-specific notes

Even though older Opera versions don't support Object.getPrototypeOf() yet, Opera supports the non-standard __proto__ property since Opera 10.50.

See also

License

© 2016 Mozilla 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

ECMAScript5 JavaScript Method Object