This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment