© Russ Ferguson and Keith Cirkel 2017

Russ Ferguson and Keith Cirkel, JavaScript Recipes, 10.1007/978-1-4302-6107-0_16

16. Working with Proxies

Russ Ferguson and Keith Cirkel2

(1)Ocean, New Jersey, USA

(2)London, UK

When Should You Use a Proxy?

Problem

What is a proxy and when should you use one?

Solution

A proxy object allows you to customize the behavior of an object. Some of the ways you can use a proxy is for interception of an object, object virtualization, profiling, and contracts for object use.

The Code

Listing 16-1. Creating and Using a Proxy
var handler = {        set (target, key, value){                  console.info(`property "${key} set on object "${target}" with a value of "${value}"`);        }}var target = {};var proxy = new Proxy(target, ...

Get JavaScript Recipes: A Problem-Solution Approach 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.