The apply(target, thisValue, arguments) method

If the target is a function, then calling the proxy will execute the apply trap. The apply trap is also executed for the function's apply() and call() methods, and the Reflect.apply() method.

The apply trap takes three parameters. The first parameter is the target object and the third parameter is an array, representing the arguments of the function call.

The second parameter is the same as the value of this of the target function--that is, it's the same as the value of this of the target function if the target function would have been invoked without the proxy.

Here is a code example that demonstrates how to use the apply trap:

const proxy = new Proxy(function(){}, {  apply(target, thisValue, ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.