Reflect
.apply()
정적 메서드는 대상 함수를 주어진 매개변수로 호출합니다.
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.apply(target, thisArgument, argumentsList)
매개변수
target
- 호출할 대상 함수.
thisArgument
- 호출에서
target
의this
로 사용할 값. argumentsList
target
을 호출할 때 매개변수로 전달할 배열형 객체.
반환 값
주어진 this
값과 매개변수로 대상 함수를 호출한 결과.
예외
target
이 호출 가능한 객체가 아니면 TypeError
.
설명
ES5에서는 Function.prototype.apply()
메서드를 사용해, 함수를 호출할 때 this
값을 지정하거나 매개변수를 배열(또는 배열형 객체)에서 넘겨줄 수 있었습니다.
Function.prototype.apply.call(Math.floor, undefined, [1.75]);
Reflect.apply()
메서드를 사용해 같은 작업을 더 쉽고 유려하게 수행할 수 있습니다.
예제
Reflect.apply()
사용하기
Reflect.apply(Math.floor, undefined, [1.75]); // 1; Reflect.apply(String.fromCharCode, undefined, [104, 101, 108, 108, 111]); // "hello" Reflect.apply(RegExp.prototype.exec, /ab/, ['confabulation']).index; // 4 Reflect.apply(''.charAt, 'ponies', [3]); // "i"
명세
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Reflect.apply' in that specification. |
Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262) The definition of 'Reflect.apply' in that specification. |
Draft |
브라우저 호환성
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.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
apply | Chrome Full support 49 | Edge Full support 12 | Firefox Full support 42 | IE No support No | Opera Full support 36 | Safari Full support 10 | WebView Android Full support 49 | Chrome Android Full support 49 | Firefox Android Full support 42 | Opera Android Full support 36 | Safari iOS Full support 10 | Samsung Internet Android Full support 5.0 | nodejs Full support 6.0.0 |
Legend
- Full support
- Full support
- No support
- No support