Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is currently possible in environments with Proxies. That would be node > 0.6 run as <code>node --harmony_proxies</code> or >0.7 with <code>node --harmony</code>. Chromium Canary (not sure if it's out of that yet) in about:flags at the bottom, experimental javascript. Firefox has had it for a while with no flags.</p> <p>So this probably won't work when ES6 becomes more official, but it works to an extent now.</p> <pre><code> var target = (function(){ var handler = Proxy.create(Proxy.create({ get: function(r, trap){ return function(name,val,c,d){ if (trap === 'get' || trap === 'set') { name = val; val = c; } console.log('"'+trap + '" invoked on property "'+name+'" ' + (val?' with value "'+val+'"':'')); switch (trap) { case 'get': return target[name]; case 'set': return target[name] = val; case 'has': return name in target; case 'delete': return delete target; case 'keys': return Object.keys(target); case 'hasOwn': return Object.hasOwnProperty.call(target, name); case 'getPropertyDescriptor': case 'getOwnPropertyDescriptor': return Object.getOwnPropertyDescriptor(target, name); case 'getPropertyNames': case 'getOwnPropertyNames': return Object.getOwnPropertyNames(target); case 'defineProperty': return Object.defineProperty(target, name, val); } } } })) var target = { x: 'stuff', f: { works: 'sure did' }, z: ['overwritten?'] }; with (handler){ var z = 'yes/no'; if (x) { //x } else { x = true; } console.log(f.works); if (f.works) { f.works = true; delete f; } } return target })() // "getPropertyDescriptor" invoked on property "z" // "getPropertyDescriptor" invoked on property "z" // "getPropertyDescriptor" invoked on property "x" // "get" invoked on property "x" // "getPropertyDescriptor" invoked on property "console" // "getPropertyDescriptor" invoked on property "f" // "get" invoked on property "f" // sure did // "getPropertyDescriptor" invoked on property "f" // "get" invoked on property "f" // "getPropertyDescriptor" invoked on property "f" // "get" invoked on property "f" // "getPropertyDescriptor" invoked on property "f" target: { x: 'Stuff', f: { works: true }, z: ['overwritten?'] } </code></pre> <p>Hit or miss and you need to take care not to blow up your browser by simply looking at a Proxy in the debugger. I had to wrap that thing in a closure to keep the proxy from ending up in the global scope or it crashed the frame every single time. Point is that it works to some extent, where nothing else does.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload