JavaScript handler.getPrototypeOf() Method

Last Updated : 15 Jun 2026

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.

What is JavaScript handler.getPrototypeOf() Method?

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).

Syntax of JavaScript handler.getPrototypeOf() Method

Use the following syntax to define a getPrototypeOf() trap in a Proxy handler:

Parameters

The getPrototypeOf() method accepts the following parameter.

  • target - The target object whose prototype is being requested.

Return Type/Value

The getPrototypeOf() method returns an object or null.

  • Returns an object representing the prototype of the target object.
  • Returns null if the object does not have a prototype.

Examples of JavaScript handler.getPrototypeOf() Method

The following examples demonstrate how to use the handler.getPrototypeOf() trap with Proxy objects.

Example 1: Return a Custom Prototype

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

Example 2: Customize instanceof Behavior

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

Example 3: Retrieve a Custom Prototype Object

In this example, the getPrototypeOf() trap returns a predefined prototype object, and the result is verified using Object.getPrototypeOf().

Output:

true

Browser Support

The following table shows the browser support for the handler.getPrototypeOf() method.

BrowserVersion
ChromeNo
EdgeNo
Firefox49
OperaNo