JS: Proxy (ES2015)

By Xah Lee. Date: . Last updated: .

2016-11-08 this page is work in progress

New in ES2015.

proxy is like a wrapper to js objects. It lets you change the behavior of things that act on a object.

Proxy object is used to

creat new proxy like this:

var = new Proxy(target , handler)
// object
var tt = {x:3};

// we want to change the behavior of accessing properties of tt


// the “handler”
var hh = {
   get: function(tt, propertyName, receiver) {
       return 99;
   }
};

// create proxy object.
var pr = new Proxy ( tt, hh );
// this will target tt, with handler hh

// access a property
console.log(pr.x); // prints 99

console.log(pr.y); // prints 99

ECMAScript 2015 §Reflection#sec-proxy-constructor

Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

Patreon me $5. Ask me question on patreon