Last Updated : 12 Jul, 2025
JavaScript handler.getOwnPropertyDescriptor() method in Javascript is a trap for the Object.getOwnPropertyDescriptor() method. A property cannot be reported as non-existent if it exists as a non-configurable own property of the target object.
Syntax:
const p = new Proxy(target, { getOwnPropertyDescriptor: function(target, prop) { } });
Parameters: This method accepts two parameters as mentioned above and described below:
Return value: This method returns an object or undefined.
Below examples illustrate the handler.getOwnPropertyDescriptor() method in JavaScript:
Example 1: In this example, we will see the use of handler.getOwnPropertyDescriptor() method in JavaScript.
javascript
const monster1 = {
num: 4
};
const handler1 = {
getOwnPropertyDescriptor(target, prop) {
console.log(`Type : ${prop}`);
return { configurable: true,
enumerable: true,
value: 5 };
}
};
const proxy1 = new Proxy(monster1, handler1);
console.log(Object.getOwnPropertyDescriptor(proxy1, 'num').value);
console.log(Object.getOwnPropertyDescriptor(proxy1, 'bool').enumerable);
Type : num 5 Type : bool true
Example 2: In this example, we will see the use of handler.getOwnPropertyDescriptor() method in JavaScript.
javascript
const p = new Proxy({ VAL: 20 }, {
getOwnPropertyDescriptor: function (target, prop) {
console.log('Property : ' + prop);
return { configurable: true, enumerable: true, value: 10 };
}
});
console.log(Object.getOwnPropertyDescriptor(p, 'VAL').value);
const obj = { a: 10 };
Object.preventExtensions(obj);
const pval = new Proxy(obj, {
getOwnPropertyDescriptor: function (target, prop) {
return undefined;
}
});
console.log(Object.getOwnPropertyDescriptor(pval));
Property : VAL 10 undefinedSupported Browsers:
The browsers are supported by handler.getOwnPropertyDescriptor() method is listed below:
We have a complete list of Javascript Proxy/handler methods, to check those go through the Javascript Proxy/handler Reference article.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4