How to access the target (which is myArray
) of myProxy
here?
function createProxy() {
const myArray = [Math.random(), Math.random()];
return new Proxy(myArray, {});
}
const myProxy = createProxy();
I'd like to have a getProxyTarget
function that would return the original object without modifying any other part of the code:
let original;
function createProxy() {
const myArray = [Math.random(), Math.random()];
original = myArray;
return new Proxy(myArray, {});
}
const myProxy = createProxy();
function getProxyTarget(proxy){ /* ... your code */ }
console.log(getProxyTarget(myProxy) === original) // should be true