[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/apply [Back]  [Original]

handler.apply() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

handler.apply()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 9.

handler.apply() .

In this article

function sum(a, b) {
  return a + b;
}

const handler = {
  apply: function (target, thisArg, argumentsList) {
    console.log(`Calculate sum: ${argumentsList}`);
    // Expected output: "Calculate sum: 1,2"

    return target(argumentsList[0], argumentsList[1]) * 10;
  },
};

const proxy1 = new Proxy(sum, handler);

console.log(sum(1, 2));
// Expected output: 3
console.log(proxy1(1, 2));
// Expected output: 30

js
var p = new Proxy(target, {
  apply: function (target, thisArg, argumentsList) {},
});

apply() . this .

target

thisArg

this

argumentsList

apply() .

handler.apply() .

.

TypeError .

. , .

.

js
const p = new Proxy(function () {}, {
  apply(target, thisArg, argumentsList) {
    console.log(`called: ${argumentsList}`);
    return argumentsList[0] + argumentsList[1] + argumentsList[2];
  },
});

console.log(p(1, 2, 3)); // ": 1,2,3"
// 6

Specification
ECMAScript 2027 LanguageSpecification
# sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist


Web Proxy Viewer  |  New URL  |  Original Page