JavaScript | Reflect.getPrototypeOf() Method
The Reflect.getPrototypeOf() method in JavaScript is used to return the prototype of the specified object.
Syntax:
Reflect.getPrototypeOf( obj )
Parameters: This method accepts single parameter as mentioned above and described below:
- obj: This parameter is the target object and it is used to get the prototype.
Return value: This method is used to get the returned the prototype of the given object.
Exceptions: A TypeError is exception given as the result, when the target is invalid.
Below examples illustrate the Reflect.getPrototypeOf() method in JavaScript:
Example 1:
javascript
<script> const object1 = { property1: 356 }; const result = Reflect.getPrototypeOf(object1); console.log(result); console.log(Reflect.getPrototypeOf(result)); const result1 = Object.create ( null ); console.log ( Reflect.getPrototypeOf ( result1 ) === null ); </script> |
Output:
Object { } null true
Example 2:
javascript
<script> console.log (Reflect.getPrototypeOf({})); console.log (Reflect.getPrototypeOf(Object.prototype)); console.log (Reflect.getPrototypeOf(Object.create( null ))); </script> |
Output:
Object { } null null
Supported Browsers: The browsers supported by JavaScript Reflect.getPrototypeOf() Method are listed below:
- Google Chrome 49 and above
- Edge 12 and above
- Firefox 42 and above
- Opera 36 and above
- Safari 10 and above