public
Last active

  • Download Gist
retargetableProxy.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// A retargetable proxy
 
function retargetableProxy(target) {
function setTarget(obj) {
target = obj;
}
 
var handler = {
get: function (_, name) {
return target[name];
},
set: function (_, name, value) {
target[name] = value;
},
getOwnPropertyDescriptor: function (_, name) {
var desc = Object.getOwnPropertyDescriptor(target, name);
if (desc)
desc.configurable = true;
return desc;
},
isExtensible: function (_) {
return true;
}
// ...
};
return [new Proxy({}, handler), setTarget];
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.