February 2018
Intermediate to advanced
298 pages
8h 22m
English
The getPrototypeOf trap is executed when we retrieve the value of the internal [[prototype]] property, using either the Object.getPrototypeOf() method or the __proto__ property. It takes only one parameter--that is, the target object.
It must return an object or null value. The null value indicates that the object doesn't inherit anything else and is the end of the inheritance chain.
Here is a code example that demonstrates how to use the getPrototypeOf trap:
const proxy = new Proxy({ age: 12, __proto__: {name: "Eden"}}, { getPrototypeOf(target) { return Object.getPrototypeOf(target); } }); console.log(Reflect.getPrototypeOf(proxy).name); //Output "Eden"
Read now
Unlock full access