Member-only story

Getting Started with Modern JavaScript — Proxy

Michael Karén
3 min readSep 8, 2020

--

Photo by Ken Suarez on Unsplash

JavaScript proxies were introduced in 2015 with ECMAScript 6. They allow us to intercept and override operations such as object property lookup and assignment. A Proxy object wraps another object and acts as a middleman.

Syntax

A proxy is created using the new Proxy constructor with two required arguments: the target and the handler.

let proxy = new Proxy(target, handler)
  • target — The object we wrap.
  • handler — An object that defines the methods (also called traps) to control the behaviors of the target.

A Proxy creates an undetectable barrier around the target object that redirects all operations to the handler object. If we send in an empty handler, the proxy is just an empty wrapper around the original object.

--

--

Michael Karén
Michael Karén

Written by Michael Karén

Frontend Architect • JavaScript Enthusiast • Educative.io Author • ngVikings organizer.

Responses (2)