Hi I was wondering if anyone knew how to get an array out of a proxy's target value in JavaScript. I have something like this :
Proxy : [[target]] : Array // the array I need to extract [[handler]] : Object [[IsRevoked]] : false
CodePudding user response:
If all you have is a reference to the proxy, there is no way (by default) for you to get the proxy's target. A specific proxy could provide a way (via one of its trap handlers, probably), but there is none by default.
CodePudding user response:
As an addition, you may get a copy of the target by spreading if the handler maps everything accordingly. But you can not get the original [[target]]
object.
const proxy = new Proxy([1, 2, 3], {
get(target, prop, receiver) {
return target[prop];
}
});
console.log([...proxy]);