TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript handler getOwnPropertyDescriptor() Method

JavaScript handler getOwnPropertyDescriptor() Method with examples on javascript handler, javascript methods, javascript tutorial, apply(), construct(), defineProperty(), deleteProperty(), get(), setPrototypeOf(), set(), ownKeys(), isExtensible() etc.

<< Back to JAVASCRIPT

JavaScript handler.getOwnPropertyDescriptor() Method

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

Syntax

getOwnPropertyDescriptor: function(target, prop)

Parameters

Target: The target object.

Prop: The name of the property whose description should be retrieved.

Return value

This method returns an object or undefined.

Browser Support

Chrome 49
Edge 12
Firefox 18
Opera 36

Example 1

const 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'));
Test it Now

Output:

Java Script is a scripting language

Example 2

const 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); 
Test it Now

Output:

Value : abc 10

Example 3

var 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);
Test it Now

Output:

Java Script proxt : Own property 50

Next TopicJavaScript handler




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf