handler.apply()
handler.apply()
메소드는 함수호출 시를 위한 트랩(trap)이다.
문법
var p = new Proxy(target, {
apply: function(target, thisArg, argumentsList) {
}
});
인자
apply 메소드에는 다음과 같은 인자가 들어온다.. this는
handler를 가리킨다.
target
- 대상이 되는 객체(함수)
thisArg
- 호출 시 바인딩 된 this
argumentsList
- 호출 시 전달된 인자목록.
반환 값
apply
메소드는 어떤 값이든 반환할 수 있다.
설명
handler.apply
메소드는 함수호출 시를 위한 트랩이다.
가로채기
이 트랩은 다음과 같은 것들을 가로챌 수 있다:
proxy(...args)
Function.prototype.apply()
와Function.prototype.call()
Reflect.apply()
기본(불변)조건
handler.apply
메소드에 대한 특별히 지켜야 할 기본조건은 없다.
예제
다음의 코드는 함수 호출 시에 트랩을 건다.
var p = new Proxy(function() {}, {
apply: function(target, thisArg, argumentsList) {
console.log('호출됨: ' + argumentsList.join(', '));
return argumentsList[0] + argumentsList[1] + argumentsList[2];
}
});
console.log(p(1, 2, 3)); // "호출됨: 1, 2, 3"
// 6
관련 명세
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of '[[Call]]' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of '[[Call]]' in that specification. |
Living Standard |
브라우저별 호환성
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 | 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) | ? | ? | ? |