The handler.get()
method is a trap for getting a property value.
var p = new Proxy(target, { get: function(target, property, receiver) { } });
The following parameters are passed to the get
method. this
is bound to the handler.
target
property
Symbol
of the property to get. receiver
The get
method can return any value.
The handler.get
method is a trap for getting a property value.
This trap can intercept these operations:
proxy[foo]
and proxy.bar
Object.create(proxy)[foo]
Reflect.get()
If the following invariants are violated, the proxy will throw a TypeError
:
The following code traps getting a property value.
var p = new Proxy({}, { get: function(target, property, receiver) { console.log('called: ' + property); return 10; } }); console.log(p.a); // "called: a" // 10
The following code violates an invariant.
var obj = {}; Object.defineProperty(obj, 'a', { configurable: false, enumerable: false, value: 10, writable: false }); var p = new Proxy(obj, { get: function(target, property) { return 20; } }); p.a; // TypeError is thrown
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of '[[Get]]' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262) The definition of '[[Get]]' in that specification. | Draft |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 49 | 12 | 18 | No | 36 | 10 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 49 | 49 | Yes | 18 | 36 | 10 | 5.0 |
Server | |
---|---|
Node.js | |
Basic support | 6.0.0 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/get