Object.getPrototypeOf()
method returns the prototype (i.e. the value of the internal
[[Prototype]]
property) of the specified object.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Object.getPrototypeOf(obj)
obj
The object whose prototype is to be returned.
The prototype of the given object. If there are no inherited properties,
null
被返回。
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)
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Object.getPrototypeOf' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getPrototypeOf
|
Chrome 5 | Edge 12 | Firefox 3.5 | IE 9 | Opera 12.1 | Safari 5 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 12.1 | Safari iOS 5 | Samsung Internet Android 1.0 | nodejs 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()
Object
Object.assign()
Object.create()
Object.defineProperties()
Object.defineProperty()
Object.entries()
Object.freeze()
Object.fromEntries()
Object.getOwnPropertyDescriptor()
Object.getOwnPropertyDescriptors()
Object.getOwnPropertyNames()
Object.getOwnPropertySymbols()
Object.getPrototypeOf()
Object.is()
Object.isExtensible()
Object.isFrozen()
Object.isSealed()
Object.keys()
Object.preventExtensions()
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.seal()
Object.setPrototypeOf()
Object.values()
Function