JavaScript Proxy

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

A Proxy in JavaScript can be used to modify fundamental operations on objects. Proxies were introduced in ES6. A Proxy on an object is itself an object, that has traps. Traps may be triggered when operations are performed on the Proxy. This includes property lookup, function calling, modifying properties, adding properties, et cetera. When no applicable trap is defined, the operation is performed on the proxied object as if there was no Proxy.

Syntax

  • let proxied = new Proxy(target, handler);

Parameters

ParameterDetails
targetThe target object, actions on this object (getting, setting, etc...) will be routed trough the handler
handlerAn object that can define "traps" for intercepting actions on the target object (getting, setting, etc...)

Remarks

A full list of available "traps" can be found on MDN - Proxy - "Methods of the handler object".



Got any JavaScript Question?