Proxies 1

V8 currently implements the same Proxy API as Firefox. The API for proxies has changed a bit since then so be extra careful when testing this.

Proxies are a very low lever construct. The are very powerful and they allow an object to intercept any access to its properties as well as intercept things like [[Call]] and [[Construct]]. There are some limitations though; the [[Prototype]] cannot change once created and there is currently no way to intercept internal properties such as [[Class]].

The basic idea is that you create a new object (the proxy) that has a handler. The handler has a bunch of functions that will get called when different operations are done to the proxy object. For example when someone sets a property the set set trap of the proxy is called.

var handler = {
  set: function(receiver, name, value) {
    console.log(name, 'was set to', value, 'on', receiver);
var proxy = Proxy.create(handler, {});
proxy.meaning = 42;  // Logs 'meaning' was set to 42 on [Object object]

Proxies are useful to emulate DOM as well as for doing membranes etc. I don’t expect anyone but library authors to ever have to use them directly.