Inspect inheritance
Check whether an object inherits from a particular prototype.
JavaScript · Function
Object.getPrototypeOf() returns the internal [[Prototype]] of a value. Its result is an object or null; modern JavaScript coerces primitive arguments to wrapper objects before retrieving the prototype.
Object.getPrototypeOf(obj) retrieves obj's internal [[Prototype]] value. The result is either an object or null; in current JavaScript, a primitive argument is converted to its corresponding wrapper object before the prototype is read.
Object.getPrototypeOf(obj)| Name | Type | Description |
|---|---|---|
obj | Object | The value whose prototype is returned. |
The prototype of the supplied value, which may be null.
const prototype = { greet() { return "hello"; } };
const object = Object.create(prototype);
console.log(Object.getPrototypeOf(object) === prototype); // true
console.log(Object.getPrototypeOf(Object.prototype)); // nullCreates an object with a chosen prototype, then retrieves that prototype and confirms the end of the standard object chain.
Check whether an object inherits from a particular prototype.
Walk an object's prototype chain until the result is null.
Verify the prototype assigned by Object.create() or a constructor.
Object.create()Object.setPrototypeOf()Reflect.getPrototypeOf()Object.prototype.__proto__