TheDeveloperBlog.com

Home | Contact Us

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

JavaScript handler get() Method

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

The handler.get method is a trap for getting a property value. This method takes 3 arguments.

Syntax

get: function(target, property, receiver)

Parameters

Target: The target object.

Property: Name of the property to get.

Receiver: The proxy or an object that inherits from the proxy.

Return value

This method can return any value.

Browser Support

Chrome 49
Edge 12
Firefox 18
Opera 36

Example 1

var data = { 
  "a": 11,"b": 21 }
var get = new Proxy(
  data ,  {
  	get: function(y, idx) {
         return y[idx] * 2
         document.writeln("
"); } } ) for(var z in get) { document.write(z +":") document.write(get[z]) }
Test it Now

Output:

a:22b:42

Example 2

var x = { f: 45, g:23 };
var proxy = new Proxy(x, {
  get: function(target, name, proxy) {
    document.write('In get');
     
    var value = target[name];
    if (typeof value === 'string') {
      value = value.toUpperCase();
    }
    return value;
  }
});
document.write (proxy.f);
document.write (x.g);
Test it Now

Output:

In get4523

Example 3

const r = {}
const  p = new Proxy(r, {
  get: function(target, property, receiver) {
   document.write('called: ' + property);
    return 100;
  }
});
document.write(p. a);
Test it Now

Output:

called: a100

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