Monday, June 3, 2024
63
rated 0 times [  67] [ 4]  / answers: 1 / hits: 54637  / 6 Years ago, fri, june 29, 2018, 12:00:00

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();

More From » ecmascript-6

 Answers
4

I found a great way to get the original target by defining the getPrototypeOf handler:


function createProxy() {
const myArray = [Math.random(), Math.random()];
return new Proxy(myArray, {
getPrototypeOf(target) {
return target;
}
});
}

const myProxy = createProxy();
const target = Object.getPrototypeOf(myProxy); // will get the original array

[#54094] Monday, June 25, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rylee

Total Points: 658
Total Questions: 114
Total Answers: 116

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
;