You cannot proxy a full object with all the traps but you can create proxied properties for get and set at least.
var proxy = {}
Object.defineProperty(proxy, 'a', {
get: function() { return bValue; },
set: function(newValue) { bValue = newValue; }
});
You can even wrap it around a method
function proxyVar(obj, key, initVal) {
Object.defineProperty(obj, key, {
get: function() { return bValue*2; },
set: function(newValue) { bValue = newValue; }
value: initVal
});
}
And then:
var proxy = {}
proxyVar(proxy, 'a', 10)
console.log(proxy.a) // prints 20
proxy.a = 20
console.log(proxy.a) // prints 40