JavaScript handler.getPrototypeOf() Method

The handler.getPrototypeOf function serves as a trap for the internal method. In cases where the target is not extensible, this function will yield an identical result to that of Object.getPrototypeOf(target).

Syntax

Example

getPrototypeOf(target)

Parameters

target : The target object.

Return value

This method returns an object or null.

Browser Support

Chrome NO
Edge NO
Firefox 49
Opera NO

Example 1

Example

const obj = {};

const proto = {};

const hag = {

    getPrototypeOf(target) {

        document.writeln (target === obj);  

        document.writeln (this === hag); 

        return proto;

    }

};

const p = new Proxy(obj, hag);

document.writeln(Object.getPrototypeOf(p) === proto);

Output:

Output

true true true

Example 2

Example

var obj = {};

var p = new Proxy(obj, {

    getPrototypeOf(target) {

        return Array.prototype;

    }

});

document.write(

  

    p instanceof Array  

);

Output:

Example 3

Example

const Prototype = {

  eyeCount : 32

};

const handler = {

  getPrototypeOf(target) {

    return Prototype;

  }

};

const obj = new Proxy(Prototype, handler);

document.writeln(Object.getPrototypeOf(obj) == Prototype);

Output:

Input Required

This code uses input(). Please provide values below: