C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript handler.get() MethodThe handler.get method is a trap for getting a property value. This method takes 3 arguments. Syntaxget: function(target, property, receiver) ParametersTarget: The target object. Property: Name of the property to get. Receiver: The proxy or an object that inherits from the proxy. Return valueThis method can return any value. Browser Support
Example 1var data = { "a": 11,"b": 21 } var get = new Proxy( data , { get: function(y, idx) { return y[idx] * 2 document.writeln(" Output: a:22b:42 Example 2var 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); Output: In get4523 Example 3const r = {} const p = new Proxy(r, { get: function(target, property, receiver) { document.write('called: ' + property); return 100; } }); document.write(p. a); Output: called: a100
Next TopicJavaScript handler
|