function createProxy() {
const myArray = [Math.random(), Math.random()];
return new Proxy(myArray, {});
}
const myProxy = createProxy();
H
You can if the target is an object.
You will have to create a function in target to retrieve it, that's all.
Example:
class AnyClass {
constructor() {
this.target = this;
return new Proxy(this, this);
}
get(obj, prop) {
if (prop in obj)
return this[prop];
// your stuff here
}
getTarget() {
return this.target;
}
}
And then when you call:
let sample = new AnyClass;
console.log(sample.getTarget());
Will return you the target as you expect :)