Reflect는 자바스크립트 작업을 중간에서 가로챌 수 있는 built-in 객체다. method들은 proxy handler들과 같다. Reflect는 함수 객체가 아니므로 생성자(constructor)로 사용될 수 없다.
Description
다른 전역객체들과는 다르게, Reflect는 생성자가 아니다. 따라서 new 연산자와 함께 사용할 수 없으며 Reflect객체를 함수로 호출할 수도 없다. Reflect객체의 모든 property들과 method들은 static이다. ( Math 객체를 생각해보면 될 것이다).
Methods
Reflect 객체는 다음과 같은 static method들을 제공하는데, 이 method들의 이름은 proxy handler method들과 같다. 이 중 몇몇 method들은 Object의 method와 같다.
Reflect.apply()target함수의 호출context를this로 바인딩하여argument와 함께 호출한다.Function.prototype.apply()와 비슷하므로 참고한다.Reflect.construct()-
new연산자의 함수 버전이다.new target(...args)과 같다. Reflect.defineProperty()Object.defineProperty()와 비슷하다.Boolean을 리턴한다.Reflect.deleteProperty()delete연산자의 함수 버전이다.delete target[name]과 같다.Reflect.get()target의property값을 가져온다.Reflect.getOwnPropertyDescriptor()Object.getOwnPropertyDescriptor()와 비슷하다.target의property가 존재하면, 해당propertydescriptor를 가져온다. 만약 존재하지 않는property면undefined을 리턴한다.Reflect.getPrototypeOf()Object.getPrototypeOf()와 같다.Reflect.has()in연산자의 함수 버전이다.target에property가 존재하거나prototype-chaning과정에 존재하면true를 리턴하고, 없으면false를 리턴한다.Reflect.isExtensible()Object.isExtensible()과 같다.Reflect.ownKeys()target.hasOwnProperty가true인property의key값들을 담은 배열을 리턴한다.hasOwnProperty는Object.prototype.hasOwnProperty()를 참고한다.Reflect.preventExtensions()Object.preventExtensions()와 비슷하다.Boolean을 리턴한다.Reflect.set()target에 새로운property를 할당한다. 할당의 성공 여부에 따라Boolean을 리턴한다.Reflect.setPrototypeOf()target의prototype을 설정한다.
Specifications
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Reflect' in that specification. |
Standard | Initial definition. |
| ECMAScript Latest Draft (ECMA-262) The definition of 'Reflect' in that specification. |
Draft | Reflect.enumerate has been removed. |
Browser compatibility
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 49.0 | (Yes) | 42 (42) | No support | No support | 10 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | 49.0 | 49.0 | 42.0 (42) | No support | No support | 10 |