C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript handler.getOwnPropertyDescriptor() MethodThe handler.getOwnPropertyDescriptor() method is a trap for Object.getOwnPropertyDescriptor(). It exists as an own property of the target object and the target object is not extensible. SyntaxgetOwnPropertyDescriptor: function(target, prop) ParametersTarget: The target object. Prop: The name of the property whose description should be retrieved. Return valueThis method returns an object or undefined. Browser Support
Example 1const proxy = new Proxy({}, { getOwnPropertyDescriptor: function(target, name) { document.writeln('Java Script is a scripting language'); //expected output: Java Script is a scripting language return Object.getOwnPropertyDescriptor(target, name); } }); console.dir(Object.getOwnPropertyDescriptor(proxy, 'foo')); Output: Java Script is a scripting language Example 2const r={} const p = new Proxy(r, { getOwnPropertyDescriptor: function(target, prop) { document.write('Value : ' + prop); return { configurable: true, enumerable: true, value: 10 }; } }); document.writeln(Object.getOwnPropertyDescriptor(p, 'abc ').value); Output: Value : abc 10 Example 3var a = { eyeCount: 3 } var b = { getOwnPropertyDescriptor(target, prop) { document.writeln(`Java Script proxt : ${prop}`); return { configurable: true, value: 50}; } }; const c= new Proxy(a, b); document.writeln(Object.getOwnPropertyDescriptor(c, 'Own property').value); Output: Java Script proxt : Own property 50
Next TopicJavaScript handler
|