O'Reilly logo

Mastering JavaScript Object-Oriented Programming by Andrea Chiarelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using proxies

An alternative approach to implements data binding may be based on a new feature introduced by ECMAScript 6-proxies.

The proxy class

The proxy class allows us to create special objects that can change the default behavior when an object is accessed. When creating a proxy for an object, we can define a handler and configure traps in order to intercept accesses to its property and possibly change the standard behavior.

Let's explain the basic behavior of proxies with an example. Suppose we want to track to the console every access to the properties of an object. We can define the following handler:

var handler = { get (target, propertyName) { console.log("Getting property " + propertyName); return target[propertyName]; }, set(target, propertyName, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required