The static method Reflect.getPrototypeOf is utilized to retrieve the prototype of a given object. This method functions identically to Object.getPrototypeOf.
Syntax:
Example
Reflect.getPrototypeOf(obj)
Parameters:
Obj: This refers to the object whose prototype is to be retrieved.
Return value:
This function retrieves the prototype associated with the specified object.
Exceptions:
A TypeError may occur when an invalid target is provided, such as a numeric value, a string literal, null, or undefined.
Browser Support:
| Chrome | 49 |
|---|---|
Edge |
12 |
| Firefox | 42 |
| Opera | 36 |
Example 1
Example
// create a object with no parent
const h = Object.create (null);
console.log (
Reflect.getPrototypeOf ( h ) === null
);
Output:
Example 2
Example
const hurry1 = {
property1: 42
};
const hello = Reflect.getPrototypeOf(hurry1);
console.log(hello);
Output:
Output
[object Object] { ... }
Example 3
Example
const hurry1 = {
property1: 42
};
const hello = Reflect.getPrototypeOf(hurry1);
console.log(Reflect.getPrototypeOf(hello));
Output: