TheDeveloperBlog.com

Home | Contact Us

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

JavaScript handler ownKeys() Method

JavaScript handler ownKeys() 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.ownKeys() Method

The handler.ownKeys() method of JavaScript is used to return an enumerable object. This method is a trap for Reflect.ownKeys().

Syntax

ownKeys: function(target)

Parameters

target: The target object.

Return value

Return an enumerable object.

Browser Support

Chrome 49
Edge 12
Firefox 18
Opera 36

Example 1

<script>
var proxy1 = new Proxy({}, {
  ownKeys: function(target) {
   document.writeln(" Use handler.ownKeys() is ");
    return ['a', 'b', 'c'];
  }
});
document.writeln(Object.getOwnPropertyNames(proxy1)); 
//expected output: Use handler.ownKeys() is a,b,c
</script>
Test it Now

Output:

Use handler.ownKeys() is a,b,c

Example 2

<script>
var x = {
 Age:24,
 Count: 45
}
var y = {
  ownKeys (target) {
    return Reflect.ownKeys(target)
  }
}
var z = new Proxy(x,y);
for (let key of Object.keys(z)) 
{
  document.writeln(key);
  // expected output: Age Count
 }
</script>
Test it Now

Output:

Age Count 

Example 3

<script>
var x = { foo: 1 };
Object.defineProperty(x, 'variable', { value: 2, 
                                  writable: true,
                                enumerable: false,
                                  configurable: true } );

var proxy = new Proxy(x, {
  ownKeys: function(target, a, b) {
    document.writeln('in ownKeys method');
var names = Object.getOwnPropertyNames(target);
    //Useing Object.getOwnProperty mehod.
    var symbols = Object.getOwnPropertySymbols(target);
    return names.concat(symbols);
  }
});
document.writeln(Object.keys(proxy));
//expected.output: in ownKeys method foo 
document.writeln("
") document.writeln(Object.getOwnPropertyNames(proxy)); //expected output: in ownKeys method foo,variable </script>
Test it Now

Output:

in ownKeys method foo 
in ownKeys method foo,variable

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