Reflect.get()
정적 메서드는 객체의 속성을 가져오는 함수입니다. target[propertyKey]
와 비슷합니다.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
구문
Reflect.get(target, propertyKey[, receiver])
매개변수
target
- 속성을 가져올 대상 객체.
propertyKey
- 가져올 속성의 이름.
receiver
Optional- 대상 속성이 접근자라면
this
의 값으로 사용할 값.Proxy
와 함께 사용하면, 대상을 상속하는 객체를 사용할 수 있습니다.
반환 값
속성의 값.
예외
설명
Reflect.get
메서드는 객체 속성의 값을 가져올 수 있습니다. 속성 접근자의 함수판이라고 할 수 있습니다.
예제
Reflect.get() 사용하기
// Object
var obj = { x: 1, y: 2 };
Reflect.get(obj, 'x'); // 1
// Array
Reflect.get(['zero', 'one'], 1); // "one"
// handler 매개변수와 Proxy
var x = {p: 1};
var obj = new Proxy(x, {
get(t, k, r) { return k + 'bar'; }
});
Reflect.get(obj, 'foo'); // "foobar"
명세
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Reflect.get' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of 'Reflect.get' in that specification. |
Living Standard |
브라우저 호환성
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.