Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

handler.get()

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

The handler.get() method is a trap for getting a property value.

Syntax

var p = new Proxy(target, {
  get: function(target, property, receiver) {
  }
});

Parameters

The following parameters are passed to the get method. this is bound to the handler.

target
The target object.
property
The name of the property to get.
receiver
Either the proxy or an object that inherits from the proxy.

Return value

The get method can return any value.

Description

The handler.get method is a trap for getting a property value.

Interceptions

This trap can intercept these operations:

  • Property access: proxy[foo]and proxy.bar
  • Inherited property access: Object.create(proxy)[foo]
  • Reflect.get()

Invariants

If the following invariants are violated, the proxy will throw a TypeError:

  • The value reported for a property must be the same as the value of the corresponding target object property if the target object property is a non-writable, non-configurable data property.
  • The value reported for a property must be undefined if the corresponding target object property is non-configurable accessor property that has undefined as its [[Get]] attribute.

Examples

The following code traps getting a property value.

var p = new Proxy({}, {
  get: function(target, prop, receiver) {
    console.log("called: " + prop);
    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, prop) {
    return 20;
  }
});

p.a; // TypeError is thrown

Specifications

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of '[[Get]]' in that specification.
Standard Initial definition.
ECMAScript 2017 Draft (ECMA-262)
The definition of '[[Get]]' in that specification.
Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? 18 (18) ? ? ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? 18.0 (18) ? ? ?

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: fscholz, arai
 최종 변경: fscholz,