The JavaScript handler.getPrototypeOf() method is a Proxy trap used to intercept operations that retrieve the prototype of an object. It allows you to customize the value returned when the prototype of a proxied object is requested.
In this chapter, you will learn how to use the handler.getPrototypeOf() trap to control prototype access through Proxy objects.
The handler.getPrototypeOf() method is a trap for internal prototype retrieval operations such as Object.getPrototypeOf(). Whenever the prototype of a Proxy object is requested, this trap is invoked.
If the target object is not extensible, the trap must return the same prototype as Object.getPrototypeOf(target).
Use the following syntax to define a getPrototypeOf() trap in a Proxy handler:
The getPrototypeOf() method accepts the following parameter.
The getPrototypeOf() method returns an object or null.
The following examples demonstrate how to use the handler.getPrototypeOf() trap with Proxy objects.
In this example, we create a Proxy object with a getPrototypeOf() trap that returns a custom prototype object whenever the prototype is requested.
Output:
true true true
In this example, the getPrototypeOf() trap returns Array.prototype, causing the Proxy object to behave as if it were an instance of Array.
Output:
true
In this example, the getPrototypeOf() trap returns a predefined prototype object, and the result is verified using Object.getPrototypeOf().
Output:
true
The following table shows the browser support for the handler.getPrototypeOf() method.
| Browser | Version |
|---|---|
| Chrome | No |
| Edge | No |
| Firefox | 49 |
| Opera | No |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India